<?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; nginx</title>
	<atom:link href="http://www.cslog.cn/tag/nginx/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>再談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>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>
	</channel>
</rss>

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