<?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/" 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/</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/#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/">继续阅读 <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/">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/</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/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>再谈Nginx Rewrite， 中文URL和其它</title>
		<link>http://www.cslog.cn/Content/nginx-rewrite-chinese/</link>
		<comments>http://www.cslog.cn/Content/nginx-rewrite-chinese/#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/">继续阅读 <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/">http://www.cslog.cn/Content/nginx-rewrite-chinese/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/nginx-rewrite-chinese/feed/</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/</link>
		<comments>http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/#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/">继续阅读 <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/">http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/feed/</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/</link>
		<comments>http://www.cslog.cn/Content/ubuntu-10-04-nginx-0-8-52-php-fpm-5-3-3-apc-mysql-i/#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/">继续阅读 <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/">http://www.cslog.cn/Content/ubuntu-10-04-nginx-0-8-52-php-fpm-5-3-3-apc-mysql-i/</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/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
