<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>船長日誌 &#187; 服務器</title>
	<atom:link href="http://www.cslog.cn/tag/%e6%9c%8d%e5%8a%a1%e5%99%a8/feed/zh-hant/" rel="self" type="application/rss+xml" />
	<link>http://www.cslog.cn</link>
	<description>最讓我激動的是不知道下一個星球上能發現什麼...</description>
	<lastBuildDate>Wed, 30 Jul 2025 16:06:05 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>推薦一個不錯的nginx教程</title>
		<link>http://www.cslog.cn/Content/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aa%e4%b8%8d%e9%94%99%e7%9a%84nginx%e6%95%99%e7%a8%8b/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aa%e4%b8%8d%e9%94%99%e7%9a%84nginx%e6%95%99%e7%a8%8b/zh-hant/#comments</comments>
		<pubDate>Fri, 02 Aug 2013 15:31:36 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[教程]]></category>
		<category><![CDATA[服務器]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=1186</guid>
		<description><![CDATA[推薦一個不錯的nginx服務器軟件教程： http://openresty.or &#8230; <a href="http://www.cslog.cn/Content/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aa%e4%b8%8d%e9%94%99%e7%9a%84nginx%e6%95%99%e7%a8%8b/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>推薦一個不錯的nginx服務器軟件教程： <a href="http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html">http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html</a></p>
<p>這個nginx教程很有點特別。作者製作了一個獨特的軟件包（openresty），將nginx和一些第三方modules合在一起，產生一個獨立的網頁程序平台。。。 所以這個nginx教程讀起來會更新是一個腳本語言教程。不過這倒提供了一個很特別的切入nginx配置語法的視角。作者深入淺出，語言簡明，而且很多例子代碼。總之是非常難得的教程。可惜的是教程應該還在寫作過程中，還不完整。期待早日有完整版本現世。
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aa%e4%b8%8d%e9%94%99%e7%9a%84nginx%e6%95%99%e7%a8%8b/zh-hant/">http://www.cslog.cn/Content/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aa%e4%b8%8d%e9%94%99%e7%9a%84nginx%e6%95%99%e7%a8%8b/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aa%e4%b8%8d%e9%94%99%e7%9a%84nginx%e6%95%99%e7%a8%8b/feed/zh-hant/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linode上各個VPS的流量限制是共享的</title>
		<link>http://www.cslog.cn/Content/linode%e4%b8%8a%e5%90%84%e4%b8%aavps%e7%9a%84%e6%b5%81%e9%87%8f%e9%99%90%e5%88%b6%e6%98%af%e5%85%b1%e4%ba%ab%e7%9a%84/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/linode%e4%b8%8a%e5%90%84%e4%b8%aavps%e7%9a%84%e6%b5%81%e9%87%8f%e9%99%90%e5%88%b6%e6%98%af%e5%85%b1%e4%ba%ab%e7%9a%84/zh-hant/#comments</comments>
		<pubDate>Mon, 04 Mar 2013 10:15:45 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[linode]]></category>
		<category><![CDATA[vps]]></category>
		<category><![CDATA[服務器]]></category>
		<category><![CDATA[站長]]></category>
		<category><![CDATA[網站空間]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=1141</guid>
		<description><![CDATA[更新：就在這兩天，Linode上的流量限制提高到了原來的10倍。看來大多數站長不 &#8230; <a href="http://www.cslog.cn/Content/linode%e4%b8%8a%e5%90%84%e4%b8%aavps%e7%9a%84%e6%b5%81%e9%87%8f%e9%99%90%e5%88%b6%e6%98%af%e5%85%b1%e4%ba%ab%e7%9a%84/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>更新：就在這兩天，Linode上的流量限制提高到了原來的10倍。看來大多數站長不用再關注Linode的流量限制問題了。</strong></p>
<p><a href="http://www.linode.com/?r=c59c1d797e6bb4212471c1b7418e8f2d2dab45b6">Linode</a>是目前為止我感覺最好用的網站空間提供商。2年多的使用體驗讓我很滿意。但到今天才知道原來Linode上各個vps的流量是共享的。也就是說如果有2個Linode 512，流量是200GB/月x2,共400GB。如果其中一個VPS做mysql數據服務器，另一個做頁面前端服務器，那個數據服務器有可能產生接近0的流量（Linode之間的內網流量不計在流量限額之內），而另一個vps就可以使用掉餘下的所有400GB流量，而不是說明中的200GB。</p>
<p>以下是所有我所知的關於Linode流量限制相關的信息：<br />
1.Linode上的VPS有流量限制， 512的是200GB, 1G的是400GB，隨價格的上升線性增加。<br />
2.多個Linode之間的VPS內部傳輸流量不計入流量限制計算。<br />
3.上傳到Linode的流量不計入流量限制計算，只計算從Linode下載的數據流量。<br />
4.所有Linode之間的流量是加在一起共享的。如上文所詳述。<br />
5.如果你網站的流量超出限額，會在次月初被加收額外的費用。收費標準是0.1美元每GB。（這個價格同Additional Transfer 100GB 10美元一個月的標準是相當的。）<br />
6.你可以在Extras中添加如上的Additional Transfer，這個是按天收費的。比如你選100GB 10美元一個月的選項，如果當月只有3天了，你只會被收1美元，同時你得到的額外流量也只有10GB。如果你在使用不到一個月前取消這個功能，Linode.com也會退回餘下天數的錢，並收回餘下天數的額外流量。個人感覺不用使用這個功能，原因參看上條。</p>
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/linode%e4%b8%8a%e5%90%84%e4%b8%aavps%e7%9a%84%e6%b5%81%e9%87%8f%e9%99%90%e5%88%b6%e6%98%af%e5%85%b1%e4%ba%ab%e7%9a%84/zh-hant/">http://www.cslog.cn/Content/linode%e4%b8%8a%e5%90%84%e4%b8%aavps%e7%9a%84%e6%b5%81%e9%87%8f%e9%99%90%e5%88%b6%e6%98%af%e5%85%b1%e4%ba%ab%e7%9a%84/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/linode%e4%b8%8a%e5%90%84%e4%b8%aavps%e7%9a%84%e6%b5%81%e9%87%8f%e9%99%90%e5%88%b6%e6%98%af%e5%85%b1%e4%ba%ab%e7%9a%84/feed/zh-hant/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>再談Nginx Rewrite， 中文URL和其它</title>
		<link>http://www.cslog.cn/Content/nginx-rewrite-chinese/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/nginx-rewrite-chinese/zh-hant/#comments</comments>
		<pubDate>Fri, 29 Jun 2012 15:36:17 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[信息處理]]></category>
		<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[nginx中文url重寫]]></category>
		<category><![CDATA[nginx的utf8支持]]></category>
		<category><![CDATA[nginx重寫]]></category>
		<category><![CDATA[pcre]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[unicode]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[url重寫]]></category>
		<category><![CDATA[utf8]]></category>
		<category><![CDATA[中文]]></category>
		<category><![CDATA[中文url]]></category>
		<category><![CDATA[服務器]]></category>
		<category><![CDATA[漢字編碼]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=1058</guid>
		<description><![CDATA[上次談到過Nginx和中文URL的問題，這幾天又加深了認識。 多分享幾個關於Ng &#8230; <a href="http://www.cslog.cn/Content/nginx-rewrite-chinese/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>上次談到過<a href="http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/">Nginx和中文URL的問題</a>，這幾天又加深了認識。 多分享幾個關於Nginx Rewrite的經驗。</p>
<p>Nginx匹配指定中文URL的方法：<br />
<code><br />
rewrite "(*UTF8)^\x{66f4}\x{6539}$" /index.html last;<br />
</code><br />
這個會將 http://www.cslog.cn/%E6%9B%B4%E6%94%B9 重定向到http://www.cslog.cn/index.html。<br />
&#8216;/%E6%9B%B4%E6%94%B9&#8242;是中文URL ‘/更改’， \x{66f4}\x{6539}是這兩個漢字的Unicode編碼。</p>
<p>注意配合PCRE 7.9以上版本使用，詳細看<a href="http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/">Nginx和中文URL的問題</a>。<br />
<span id="more-1058"></span><br />
Nginx匹配URL中中文參數的方法：<br />
如果要將 http://www.cslog.cn/index.php?title=%E6%9B%B4%E6%94%B9 重定向到http://www.cslog.cn, 則要使用<br />
<code><br />
location = /index\.php$ {<br />
if ($args_title =%E6%9B%B4%E6%94%B9 ) {<br />
rewrite ^ /;<br />
}<br />
}<br />
</code><br />
在這裡， &#8216;?title=%E6%9B%B4%E6%94%B9&#8242; 是不能用上例那裡的rewrite捕捉到的， 而要使用$arg_參數名這樣的方式處理。 而且在這裡， &#8216;%E6%9B%B4%E6%94%B9&#8242;是不用特別轉換的，直接放上去就可以了。</p>
<p>還要注意到 location後面的 ~, *~, ^~, =或空是有不同的效果的。詳細參看<a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#location">nginx的官方手冊</a>。</p>
<p>讓Nginx在同時識別到兩個參數的情況下重定向的方法<br />
假設要在例如 http://www.cslog.cn/index.php?title=%E6%9B%B4%E6%94%B9&amp;lang=Zh-tw 這樣的URL，只有在lang=Zh-tw參數存在，並且title參數也存在（不管它的值）的情況下才重定向， 要求會苛刻些，因為nginx自身沒有並列的邏輯處理能力，但可以使用如下的方法曲線解決：<br />
<code><br />
location = /index\.php {<br />
set $redirect "";</code></p>
<p><code># 檢查是否存在"title"參數:<br />
if ( $arg_title ) {<br />
set $redirect "Y";<br />
}</p>
<p># 檢查lang參數是否為 "Zh-tw":<br />
if ( $arg_lang =Zh-tw ) {<br />
set $redirect "${redirect}ES";<br />
}</p>
<p># 看看條件是否同時成立 "YES":<br />
if ( $redirect = YES ) {<br />
rewrite ^ / last;<br />
}</p>
<p></code></p>
<p><code> ....<br />
}<br />
</code>
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/nginx-rewrite-chinese/zh-hant/">http://www.cslog.cn/Content/nginx-rewrite-chinese/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/nginx-rewrite-chinese/feed/zh-hant/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Nginx、PCRE和中文URL（UTF8編碼）rewrite路徑重寫匹配問題</title>
		<link>http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/zh-hant/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 15:08:45 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[信息處理]]></category>
		<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[nginx中文url重寫]]></category>
		<category><![CDATA[nginx的utf8支持]]></category>
		<category><![CDATA[pcre]]></category>
		<category><![CDATA[PCRE的UTF8編碼支持]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[url重寫]]></category>
		<category><![CDATA[utf8]]></category>
		<category><![CDATA[中文]]></category>
		<category><![CDATA[中文url]]></category>
		<category><![CDATA[服務器]]></category>
		<category><![CDATA[漢字編碼]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=793</guid>
		<description><![CDATA[最近遇到了使用Nginx 重寫中文UTF8編碼路徑的問題。 才發現默認情況下Ng &#8230; <a href="http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>最近遇到了使用<a href="http://www.cslog.cn/tag/nginx/">Nginx</a> 重寫中文UTF8編碼路徑的問題。 才發現默認情況下Nginx的rewrite是不支持UTF8匹配的。 比如：</p>
<p><code>rewrite ^/(..)$ /2個字符文章.html break; #用2個點</code><br />
可以匹配到 /ab 或 /51, 但 /漢字 是匹配不到的。 我測試了一下， 要匹配兩個字的 /漢字 路徑， 得用</p>
<p><code>rewrite ^/(……)$ /2個漢字文章.html break; #要用六個點</code></p>
<p>如果要讓 ^/(..)$ 匹配到2個漢字字符，得開啟Nginx對UTF8字符的正則支持， 準確點說是開啟Nginx使用的PCRE庫的對UTF8字符的支持。因為Nginx的rewrite模塊是調用PCRE來處理正則的。 如果PCRE沒有問題，Nginx支持UTF8編碼的重寫樣式是：</p>
<p><code>rewrite "(*UTF8)^/(..)$" /2個字符文章.html break;<br />
#注意(*UTF8)前綴和引號的加入。</code></p>
<p><span id="more-793"></span>因為PCRE只有7.9以上的版本才支持這個(*UTF8)開頭，所以系統上的PCRE一定要使用7.9以上的版本。 另外，編譯PCRE時一定要開啟UTF8的支持。 即使用(&#8211;enable-utf8)參數。 檢查系統的PCRE版本和是否支持UTF8編碼可以使用<br />
<code>pcretest -C</code><br />
命令。執行後會顯示如下的報告：</p>
<blockquote><p>PCRE version 8.13 2011-08-16<br />
Compiled with<br />
UTF-8 support<br />
Unicode properties support<br />
Newline sequence is LF<br />
\R matches all Unicode newlines<br />
Internal link size = 2<br />
POSIX malloc threshold = 10<br />
Default match limit = 10000000<br />
Default recursion depth limit = 10000000<br />
Match recursion uses stack</p></blockquote>
<p>顯示“UTF-8 support”就是支持UTF8編碼了。</p>
<p>如果Nginx調用的PCRE為7.9以下的版本，使用 rewrite &#8220;(*UTF8)^/(..)$&#8221; /2個字符文章.html break; 這種形式的重寫，在執行nginx -t檢查時會出現如下的錯誤提示：</p>
<blockquote><p>[emerg]: pcre_compile() failed: (*VERB) not recognized in &#8220;(*UTF8)^、……</p></blockquote>
<p>如果Nginx調用的是7.9以上版本的PCRE，但是PCRE安裝時沒打開UTF8的支持開關，則會出現如下的錯誤提示：</p>
<blockquote><p>nginx: [emerg] pcre_compile() failed: this version of PCRE is not compiled with PCRE_UTF8 support in &#8220;(*UTF8)^/&#8230;</p></blockquote>
<p>解決辦法是安裝最新版本的的PCRE，並打開UTF8支持，方法如下（以當前8.13版的PCRE為例）：<br />
<code>wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.13.tar.gz<br />
tar zxvf pcre-8.13.tar.gz<br />
cd pcre-8.13<br />
./configure --enable-utf8 --enable-unicode-properties<br />
make<br />
make install</code></p>
<p>然後重新編譯安裝Nginx。 Nginx默認會打開rewrite模塊，並會自動查找系統上已經安裝了的PCRE。 如果Nginx查找不到已經安裝在系統上的PCRE， 或者系統上有多個PCRE， nginx調用了不支持UTF8的、或低版本的PCRE時（我遇到了後一種情況，並花費了很長的時間解決這個問題，這也是我為什麼寫這篇總結文章在這裡給大家分享的原因。。。），可以在編譯安裝Nginx時指定PCRE源文件。例如：</p>
<p><code>wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.13.tar.gz<br />
tar zxvf pcre-8.13.tar.gz<br />
wget http://nginx.org/download/nginx-1.0.8.tar.gz<br />
tar zxvf nginx-1.0.8.tar.gz<br />
cd nginx-1.0.8<br />
./configure \<br />
--with-pcre=../pcre-8.13</code></p>
<p>注意，如果接着直接make &amp;&amp; make install的話， PCRE因為沒有啟用UTF8， nginx將不能支持UTF8重寫， 所以在這一種，我動了一點小手腳：打開./objs/Makefile 文件，找到以下段落：</p>
<p><code> ../pcre-8.13/Makefile:	objs/Makefile<br />
cd ../pcre-8.13 \<br />
&amp;&amp; if [ -f Makefile ]; then $(MAKE) distclean; fi \<br />
&amp;&amp; CC="$(CC)" CFLAGS="-O2 -fomit-frame-pointer -pipe " \<br />
./configure --disable-shared </code><br />
在&#8211;disable-shared後加上 &#8211;enable-utf8和 &#8211;enable-unicode-properties參數， 即變成：<br />
<code> ../pcre-8.13/Makefile:	objs/Makefile<br />
cd ../pcre-8.13 \<br />
&amp;&amp; if [ -f Makefile ]; then $(MAKE) distclean; fi \<br />
&amp;&amp; CC="$(CC)" CFLAGS="-O2 -fomit-frame-pointer -pipe " \<br />
./configure --disable-shared --enable-utf8 --enable-unicode-properties</code><br />
然後再make, make install。 最後關閉nginx並重啟nginx（這裡不能用nginx -s reload)。這樣nginx就支持中文UTF8編碼的url重寫了。
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/zh-hant/">http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/feed/zh-hant/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>使用Unicorn替代Mongrel作為Ruby on Rails的服務器</title>
		<link>http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/zh-hant/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 16:54:41 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rubyonrails]]></category>
		<category><![CDATA[unicorn]]></category>
		<category><![CDATA[服務器]]></category>
		<category><![CDATA[網站開發]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=727</guid>
		<description><![CDATA[先前的開發的Ruby on Rails網站使用的服務程序是Mongrel + N &#8230; <a href="http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>先前的開發的Ruby on Rails網站使用的服務程序是<a title="在ubuntu6.06上安裝apache2.2X + mysql + PHP + Ruby on Rails + Mongrel Cluster | 船長日誌" href="http://www.cslog.cn/Content/ubuntu606_mysql_apache2_ruby_rails_mongrel_cluster/">Mongrel + Nginx</a>， 現在用了Rails 3， 發現Mongrel對它有兼容問題， 所以要換一個。 雖然現在<a title="Overview — Phusion Passenger™ (a.k.a. mod_rails / mod_rack)" href="http://www.modrails.com/">Phusion Passenger</a>大行其道， 但使用前要重新編譯Nginx。 為了避免重新安裝nginx，我找到mongrel的替代品<a title="File: README [Unicorn: Rack HTTP server for fast clients and Unix]" href="http://unicorn.bogomips.org/">Unicorn</a>。 沒想到unicorn的設置非常方便。 我記錄在這裡供大家參考：</p>
<p>安裝unicorn:<br />
<code><br />
sudo gem install unicorn<br />
</code></p>
<p>創建網站配置文件(myproject是項目名稱):<br />
<code><span id="more-727"></span><br />
sudo mkdir /etc/unicorn<br />
cd /etc/unicorn/<br />
sudo nano /etc/unicorn/myproject.conf<br />
</code></p>
<p>內容如下：<br />
<code><br />
RAILS_ROOT=/www/myproject<br />
RAILS_ENV=production<br />
</code></p>
<p>在網站里再創建一個unicorn配置文件<br />
<code><br />
nano /www/myproject/config/unicorn.rb<br />
</code></p>
<p>內容如下：<br />
<code><br />
# Minimal sample configuration file for Unicorn (not Rack) when used<br />
# with daemonization (unicorn -D) started in your working directory.<br />
#<br />
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete<br />
# documentation.<br />
# See also http://unicorn.bogomips.org/examples/unicorn.conf.rb for<br />
# a more verbose configuration using more features.</code></p>
<p><code> </code></p>
<p><code>app_path = "/www/myproject"</code></p>
<p><code> </code></p>
<p><code>listen 8080 # by default Unicorn listens on port 8080<br />
worker_processes 2 # this should be &gt;= nr_cpus<br />
pid "#{app_path}/tmp/pids/unicorn.pid"<br />
stderr_path "#{app_path}/log/unicorn.log"<br />
stdout_path "#{app_path}/log/unicorn.log"<br />
</code></p>
<p>設置unicorn啟動腳本：<br />
<code><br />
sudo nano /etc/init.d/unicorn_init<br />
</code><br />
腳本內容：<br />
<code><br />
#!/bin/sh<br />
#<br />
# init.d script for single or multiple unicorn installations. Expects at least one .conf<br />
# file in /etc/unicorn<br />
#<br />
# Modified by jay@gooby.org http://github.com/jaygooby<br />
# based on http://gist.github.com/308216 by http://github.com/mguterl<br />
#<br />
## A sample /etc/unicorn/my_app.conf<br />
##<br />
## RAILS_ENV=production<br />
## RAILS_ROOT=/var/apps/www/my_app/current<br />
#<br />
# This configures a unicorn master for your app at /var/apps/www/my_app/current running in<br />
# production mode. It will read config/unicorn.rb for further set up.<br />
#<br />
# You should ensure different ports or sockets are set in each config/unicorn.rb if<br />
# you are running more than one master concurrently.<br />
#<br />
# If you call this script without any config parameters, it will attempt to run the<br />
# init command for all your unicorn configurations listed in /etc/unicorn/*.conf<br />
#<br />
# /etc/init.d/unicorn start # starts all unicorns<br />
#<br />
# If you specify a particular config, it will only operate on that one<br />
#<br />
# /etc/init.d/unicorn start /etc/unicorn/my_app.conf</code></p>
<p><code> </code></p>
<p><code>set -e</code></p>
<p><code>sig () {<br />
test -s "$PID" &amp;&amp; kill -$1 `cat "$PID"`<br />
}</p>
<p>oldsig () {<br />
test -s "$OLD_PID" &amp;&amp; kill -$1 `cat "$OLD_PID"`<br />
}</p>
<p>cmd () {</p>
<p>case $1 in<br />
start)<br />
sig 0 &amp;&amp; echo &gt;&amp;2 "Already running" &amp;&amp; exit 0<br />
echo "Starting"<br />
$CMD<br />
;;<br />
stop)<br />
sig QUIT &amp;&amp; echo "Stopping" &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Not running"<br />
;;<br />
force-stop)<br />
sig TERM &amp;&amp; echo "Forcing a stop" &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Not running"<br />
;;<br />
restart|reload)<br />
sig USR2 &amp;&amp; sleep 5 &amp;&amp; oldsig QUIT &amp;&amp; echo "Killing old master" `cat $OLD_PID` &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Couldn't reload, starting '$CMD' instead"<br />
$CMD<br />
;;<br />
upgrade)<br />
sig USR2 &amp;&amp; echo Upgraded &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Couldn't upgrade, starting '$CMD' instead"<br />
$CMD<br />
;;<br />
rotate)<br />
sig USR1 &amp;&amp; echo rotated logs OK &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Couldn't rotate logs" &amp;&amp; exit 1<br />
;;<br />
*)<br />
echo &gt;&amp;2 "Usage: $0 "<br />
exit 1<br />
;;<br />
esac<br />
}</p>
<p>setup () {</p>
<p>echo -n "$RAILS_ROOT: "<br />
cd $RAILS_ROOT || exit 1<br />
export PID=$RAILS_ROOT/tmp/pids/unicorn.pid<br />
export OLD_PID="$PID.oldbin"</p>
<p>CMD="/usr/bin/unicorn_rails -c config/unicorn.rb -E $RAILS_ENV -D"<br />
}</p>
<p>start_stop () {</p>
<p># either run the start/stop/reload/etc command for every config under /etc/unicorn<br />
# or just do it for a specific one</p>
<p># $1 contains the start/stop/etc command<br />
# $2 if it exists, should be the specific config we want to act on<br />
if [ $2 ]; then<br />
. $2<br />
setup<br />
cmd $1<br />
else<br />
for CONFIG in /etc/unicorn/*.conf; do<br />
# import the variables<br />
. $CONFIG<br />
setup</p>
<p># run the start/stop/etc command<br />
cmd $1<br />
done<br />
fi<br />
}</p>
<p></code></p>
<p><code>ARGS="$1 $2"<br />
start_stop $ARGS<br />
</code><br />
注意將裡面的/usr/bin/unicorn_rails 換成你系統中unicorn_rails程序的實際路徑。</p>
<p>設置unicorn_init文件屬性:<br />
<code><br />
sudo chmod 755 /etc/init.d/unicorn_init<br />
</code></p>
<p>啟動unicorn:<br />
<code><br />
/etc/init.d/unicorn_init<br />
</code></p>
<p>修改nginx的配置文件，加入unicorn的代理設置：<br />
<code><br />
upstream myproject_mongrel {<br />
server 127.0.0.1:8080 fail_timeout=0;<br />
}<br />
</code><br />
這部分跟使用mongrel的類似的。</p>
<p>這樣unicorn的設置就完成了。 剛設置好，感覺unicorn跟mongrel一樣， 都是比較吃內存的， 一啟動就佔了50M. 不知道會不會也像mongrel一樣把內存吃爆， 會得話得設置監控軟件（如god）看住它。
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/zh-hant/">http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/feed/zh-hant/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ubuntu 10.04 上安裝Nginx 0.8.52 + PHP-fpm 5.3.3 + APC和MySQL</title>
		<link>http://www.cslog.cn/Content/ubuntu-10-04-nginx-0-8-52-php-fpm-5-3-3-apc-mysql-i/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/ubuntu-10-04-nginx-0-8-52-php-fpm-5-3-3-apc-mysql-i/zh-hant/#comments</comments>
		<pubDate>Mon, 18 Oct 2010 17:28:19 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php-fpm]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[服務器]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=543</guid>
		<description><![CDATA[Ubuntu 10.04 上源碼編譯安裝Nginx 0.8.52 + PHP-f &#8230; <a href="http://www.cslog.cn/Content/ubuntu-10-04-nginx-0-8-52-php-fpm-5-3-3-apc-mysql-i/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ubuntu 10.04 上源碼編譯安裝Nginx 0.8.52 + PHP-fpm 5.3.3 + APC和MySQL<br />
Ubuntu 是服務器上常用的Linux發行版本. 10.04是最新的LTS版本. Nginx則是佔用內存少, 速度快的網頁server的後起之秀. PHP從5.3.3起, 內置了FPM補丁, 跟nginx的兼容性又上了一個台階. 本文是在Ubuntu 10.04上源碼編譯安裝nginx 0.8.52, PHP-fpm 5.3.3, 加APC PHP加速的操作教程. (最後使用apt-get安裝mysql數據庫).</p>
<p>注意, 整個安裝過程都是使用root帳號.</p>
<p><span id="more-543"></span></p>
<h3>第一步 安裝準備</h3>
<p>更新系統源庫和更新已經安裝過的程序:</p>
<pre>sudo apt-get update
sudo apt-get dist-upgrade</pre>
<p>安裝會用的程序:</p>
<pre>apt-get install htop binutils cpp flex gcc libarchive-zip-perl \
libc6-dev libcompress-zlib-perl m4 libpcre3 libpcre3-dev libssl-dev \
libpopt-dev lynx make perl perl-modules openssl unzip zip \
autoconf2.13 gnu-standards automake libtool bison build-essential \
zlib1g-dev ntp ntpdate autotools-dev g++ bc subversion psmisc \
libmysqlclient-dev libcurl4-openssl-dev libjpeg62-dev libpng3-dev \
libxpm-dev libfreetype6-dev libt1-dev libmcrypt-dev libxslt1-dev \
libbz2-dev libxml2-dev libevent-dev libltdl-dev libmagickwand-dev \
imagemagick</pre>
<p>創建用來臨時放源碼的目錄:</p>
<pre>mkdir ~/src
cd ~/src</pre>
<p>下載nginx和PHP等源碼:</p>
<pre>wget http://nginx.org/download/nginx-0.8.52.tar.gz
wget http://us2.php.net/distributions/php-5.3.3.tar.gz
wget http://download.suhosin.org/suhosin-patch-5.3.3-0.9.10.patch.gz
wget http://download.suhosin.org/suhosin-0.9.32.1.tar.gz
wget http://pecl.php.net/get/imagick-3.0.0.tgz</pre>
<p>解壓縮源碼包:</p>
<pre>tar zxvf nginx-0.8.52.tar.gz
tar xzvf php-5.3.3.tar.gz
tar xzvf suhosin-0.9.32.1.tar.gz
gunzip suhosin-patch-5.3.3-0.9.10.patch.gz
tar xzvf imagick-3.0.0.tgz</pre>
<h3>第二步 安裝nginx 0.8.52</h3>
<p>編譯安裝nginx:</p>
<pre>cd nginx-0.8.52/

./configure \
  --prefix=/opt/nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --pid-path=/var/run/nginx.pid \
  --lock-path=/var/lock/nginx.lock \
  --http-log-path=/var/log/nginx/access.log \
  --error-log-path=/var/log/nginx/error.log \
  --http-client-body-temp-path=/var/lib/nginx/body \
  --http-proxy-temp-path=/var/lib/nginx/proxy \
  --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
  --http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
  --http-scgi-temp-path=/var/lib/nginx/scgi \
  --with-http_ssl_module \
  --with-http_stub_status_module \
  --user=www-data \
  --group=www-data \
  --without-mail_pop3_module \
  --without-mail_imap_module \
  --without-mail_smtp_module 

make
make install
cd ..</pre>
<p>注意把nginx安裝到/opt/nginx目錄里了. nginx的配置文件在/etc/nginx/nginx.conf, pid在/var/run/nginx.pid.</p>
<p>在系統PATH里加入nginx的路徑:</p>
<pre>echo 'if [ -d "/opt/nginx/sbin" ]; then
    PATH="$PATH:/opt/nginx/sbin"
fi' &gt;&gt; /etc/bash.bashrc</pre>
<p>當前連接會話也加上:</p>
<pre>export PATH="$PATH:/opt/nginx/sbin"</pre>
<p>添加啟動管理文件並讓ubuntu開機時自動運行nginx網頁服務器, 我把修改好的腳本放到博客上了:</p>
<pre>wget http://www.cslog.cn/wp-content/uploads/2010/10/nginx.gz
gunzip nginx.gz
mv nginx /etc/init.d
chmod +x /etc/init.d/nginx
update-rc.d -f nginx defaults</pre>
<p>自動分割和壓縮nginx日誌分文:</p>
<pre>nano /etc/logrotate.d/nginx</pre>
<p>在裡面加入下面內容:</p>
<pre>/var/log/nginx/*.log {
	weekly
	missingok
	rotate 52
	compress
	delaycompress
	notifempty
	create 640 root adm
	sharedscripts
	postrotate
		[ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
	endscript
}</pre>
<p>給nginx新建運行環境目錄:</p>
<pre>mkdir /var/lib/nginx</pre>
<p>到這裡nginx的安裝完成了.</p>
<h3>第三步 安裝PHP</h3>
<p>給php打上suhosin安全補丁:</p>
<pre>cd php-5.3.3
patch -p 1 -i ../suhosin-patch-5.3.3-0.9.10.patch</pre>
<p>開始編譯安裝php 5.3.3</p>
<pre>./buildconf --force

./configure \
	--prefix=/opt/php5 \
	--with-config-file-path=/opt/php5/etc \
	--with-curl \
	--with-pear \
	--with-gd \
	--with-jpeg-dir \
	--with-png-dir \
	--with-zlib \
	--with-xpm-dir \
	--with-freetype-dir \
	--with-t1lib \
	--with-mcrypt \
	--with-mhash \
	--with-mysql \
	--with-mysqli \
	--with-pdo-mysql \
	--with-openssl \
	--with-xmlrpc \
	--with-xsl \
	--with-bz2 \
	--with-gettext \
	--with-fpm-user=www-data \
	--with-fpm-group=www-data \
	--enable-fpm \
	--enable-exif \
	--enable-wddx \
	--enable-zip \
	--enable-bcmath \
	--enable-calendar \
	--enable-ftp \
	--enable-mbstring \
	--enable-soap \
	--enable-sockets \
	--enable-sqlite-utf8 \
	--enable-shmop \
	--enable-dba \
	--enable-sysvmsg \
	--enable-sysvsem \
	--enable-sysvshm

make
make install</pre>
<p>注意, PHP5.3.3自帶了fpm補丁, 不用再打了. PHP安裝到了/opt/php5目錄.</p>
<p>將php5所在的目錄也加到bash的PATH中去:</p>
<pre>echo 'if [ -d "/opt/php5/bin" ] &amp;&amp; [ -d "/opt/php5/sbin" ]; then
    PATH="$PATH:/opt/php5/bin:/opt/php5/sbin"
fi' &gt;&gt; /etc/bash.bashrc</pre>
<p>當前會話也加上:</p>
<pre>export PATH="$PATH:/opt/php5/bin:/opt/php5/sbin"</pre>
<p>準備PHP5的日誌文件目錄:</p>
<pre>mkdir /var/log/php-fpm
chown -R www-data:www-data /var/log/php-fpm</pre>
<p>準備PHP的配置文件:</p>
<pre>cp -f php.ini-production /opt/php5/etc/php.ini
chmod 644 /opt/php5/etc/php.ini
cp /opt/php5/etc/php-fpm.conf.default /opt/php5/etc/php-fpm.conf</pre>
<p>注意: PHP5的配置文件在/opt/php5/etc/php.ini, php-fpm的配置文件在/opt/php5/etc/php-fpm.conf.</p>
<p>修改php-fpm配置文件:</p>
<pre>nano /opt/php5/etc/php-fpm.conf</pre>
<p>另外, 裡面的服務數量請根據自己的機器硬件配置和網站流量做調整設置<br />
如:</p>
<pre>pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 20</pre>
<p>如果將監聽端口設置從</p>
<pre>listen = 127.0.0.1:9000</pre>
<p>換成sock,如</p>
<pre>listen = /var/run/php-fpm.sock</pre>
<p>要做如下操作,保證php-fpm.scok的可讀性</p>
<pre>touch /var/run/php-fpm.sock
chown -R www-data:www-data /var/run/php-fpm.sock</pre>
<p>按ctl+w搜索php_fpm_PID, 將它改的值改成</p>
<pre>php_fpm_PID=/var/run/php-fpm.pid</pre>
<p>設置php-fpm啟動管理文件,並讓PHP在ubuntu啟動時自動運行:</p>
<pre>cp -f sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
update-rc.d -f php-fpm defaults</pre>
<p>修改php-fpm啟動管理文件:</p>
<pre>nano /etc/init.d/php-fpm</pre>
<p>將裡面php_fpm_PID的值也改成/var/run/php-fpm.pid:</p>
<pre>php_fpm_PID=/var/run/php-fpm.pid</pre>
<p>設置PHP的自動日誌分割和壓縮:</p>
<pre>nano /etc/logrotate.d/php-fpm</pre>
<p>加入:</p>
<pre>/var/log/php-fpm/*.log {
	weekly
	missingok
	rotate 52
	compress
	delaycompress
	notifempty
	create 640 www-data www-data
	sharedscripts
	postrotate
		[ ! -f /var/run/php-fpm.pid ] || kill -USR1 `cat /var/run/php-fpm.pid`
	endscript
}</pre>
<p>給php安裝APC加速器:</p>
<pre>pecl install APC-3.1.4</pre>
<p>和安全補丁</p>
<pre>cd ../suhosin-0.9.32.1
/opt/php5/bin/phpize
./configure --enable-suhosin
make
make test
make install</pre>
<p>給PHP安裝imagick圖像處理模塊:</p>
<pre>cd ../imagick-3.0.0
/opt/php5/bin/phpize
./configure --with-imagick
make
make test
make install</pre>
<p>向php.ini配置文件第920行下面添加新模塊信息:</p>
<pre>nano +920 /opt/php5/etc/php.ini</pre>
<p>插入:</p>
<pre>extension = suhosin.so
extension = imagick.so
extension = apc.so
apc.enabled = 1
apc.shm_size = 128M
apc.shm_segments=1
apc.write_lock = 1
apc.rfc1867 = On
apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=1024
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.enable_cli=1
;# Optional, for "[apc-warning] Potential cache slam averted for key... errors"
;apc.slam_defense = Off</pre>
<p>注意, 在修改時可以順便將時區設置成中國時區:<br />
找到<br />
[Date] 部分<br />
加入:</p>
<pre>date.timezone = Asia/Chongqing</pre>
<h3>第四步 安裝MySQL數據庫</h3>
<p>為方便省事, 使用apt-get安裝MySQL</p>
<pre>sudo apt-get install mysql-server</pre>
<p>將mysql的默認字符編碼改成utf-8,以便更好的支持中文字符:<br />
打開mysql配置文件:</p>
<pre>nano /etc/mysql/my.cnf</pre>
<p>找到[client] 添加:</p>
<pre>default-character-set=utf8</pre>
<p>找到[mysqld] 添加:</p>
<pre>default-character-set=utf8
#設定連接mysql數據庫時使用utf8編碼，以讓mysql數據庫為utf8運行
init_connect='SET NAMES utf8'</pre>
<p>重啟mysql服務：</p>
<pre>/usr/bin/mysqld_safe --user=mysql &amp;</pre>
<p>到這裡, ubuntu 10.04上nginx, php-fpm+apc和mysql的安裝全部完成了.</p>
<h3>免費附送</h3>
<p>php的啟動方法</p>
<pre>/etc/init.d/php-fpm start</pre>
<p>重啟</p>
<pre>/etc/init.d/php-fpm restart</pre>
<p>nginx的啟動方法:</p>
<pre>/etc/init.d/nginx start</pre>
<p>不間斷nginx的重新裝載新配置文件的方法:</p>
<pre>nginx -s reload</pre>
<p>重啟前最好先測試一下新配置文件</p>
<pre>nginx -t</pre>
<p>好了, 希望你的安裝順利. 遇到什麼問題可以留言.</p>
<p>參考文章 : <a href="http://vladgh.com/blog/install-nginx-and-php-533-php-fpm-mysql-and-apc">http://vladgh.com/blog/install-nginx-and-php-533-php-fpm-mysql-and-apc</a>
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/ubuntu-10-04-nginx-0-8-52-php-fpm-5-3-3-apc-mysql-i/zh-hant/">http://www.cslog.cn/Content/ubuntu-10-04-nginx-0-8-52-php-fpm-5-3-3-apc-mysql-i/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/ubuntu-10-04-nginx-0-8-52-php-fpm-5-3-3-apc-mysql-i/feed/zh-hant/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>中文文件名編碼和html文件訪問</title>
		<link>http://www.cslog.cn/Content/url-encode-and-file-name/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/url-encode-and-file-name/zh-hant/#comments</comments>
		<pubDate>Sun, 19 Sep 2010 00:27:46 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[服務器]]></category>
		<category><![CDATA[漢字編碼]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[之前用windows服務器， 上面的有中文名的html文件。 為了保證訪問， 鏈 &#8230; <a href="http://www.cslog.cn/Content/url-encode-and-file-name/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>之前用windows服務器， 上面的有中文名的html文件。 為了保證訪問， 鏈接到這些文件的URL做了中文編碼處理。 那時使用的是ASP寫的， 編碼用的是GB2312. 最近想把這個網站搬到linux服務器上. 將文件上傳到linux服務器後發現原來的鏈接訪問不到中文html文件. 到後來才想到自己linux系統上默認使用的是utf-8編碼文件系統. 後來將FTP軟件設定為GB2312編碼, 重新上傳這些文件後才問題解決了.</p>
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/url-encode-and-file-name/zh-hant/">http://www.cslog.cn/Content/url-encode-and-file-name/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/url-encode-and-file-name/feed/zh-hant/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- WP Chinese Conversion Full Page Converted -->