<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[张宴的博客]]></title> 
<link>http://zyan.cc/index.php</link> 
<description><![CDATA[Web系统架构与底层研发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[张宴的博客]]></copyright>
<item>
<link>http://zyan.cc/post/351/</link>
<title><![CDATA[Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[Web服务器]]></category>
<pubDate>Mon, 09 Jun 2008 15:08:02 +0000</pubDate> 
<guid>http://zyan.cc/post/351/</guid> 
<description>
<![CDATA[ 
	　　<strong><span style="font-size: 14px;"><span style="color: #FF0000;">本文已有最新版本：</span></span></strong><br/><br/>　　<strong><span style="font-size: 14px;"><span style="color: #FF0000;">请点击</span>《<a href="http://blog.zyan.cc/nginx_php_v6/" target="_blank">Nginx 0.8.x + PHP 5.2.13（FastCGI）搭建胜过Apache十倍的Web服务器（第6版）</a>》</span></strong><br/><br/><hr/><br/><br/>　　[文章作者：张宴 本文版本：v3.2 最后修改：<span style="color: #FF0000;">2008.07.16</span> 转载请注明原文链接：<a href="http://blog.zyan.cc/read.php/351.htm" target="_blank">http://blog.zyan.cc/read.php/351.htm</a>]<br/><br/>　　前言：本文是我撰写的关于搭建“Nginx + PHP（FastCGI）”Web服务器的第3篇文章，也是Nginx 0.6系列版本成为稳定版后的第一篇文章，安装、配置方式与以往略有不同，并增加了一些在生产环境运行中不断修改、调整，总结出的配置上的优化。<br/><br/>　　链接：《<a href="read.php/297.htm" target="_blank">2007年9月的第1版</a>》、《<a href="read.php/314.htm" target="_blank">2007年12月的第2版</a>》<br/><br/>　　<a href="http://zyan.cc/attachment/200806/nginx.png" target="_blank"><img src="http://zyan.cc/attachment/200806/nginx.png" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　<a href="http://www.nginx.net/" target="_blank">Nginx</a> ("engine x") 是一个高性能的 HTTP 和反向代理服务器，也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的，它已经在该站点运行超过两年半了。Igor 将源代码以类BSD许可证的形式发布。<br/><br/>　　Nginx 的中文维基：<a href="http://wiki.codemongers.com/NginxChs" target="_blank">http://wiki.codemongers.com/NginxChs</a><br/><br/><hr/><br/>　　在高并发连接的情况下，Nginx是Apache服务器不错的替代品。Nginx同时也可以作为7层负载均衡服务器来使用。根据我的测试结果，<strong>Nginx 0.6.31 + PHP 5.2.6 (FastCGI) 可以承受3万以上的并发连接数，相当于同等环境下Apache的10倍</strong>。<br/><br/>　　根据我的经验，4GB内存的服务器+Apache（prefork模式）一般只能处理3000个并发连接，因为它们将占用3GB以上的内存，还得为系统预留1GB的内存。我曾经就有两台Apache服务器，因为在配置文件中设置的MaxClients为4000，当Apache并发连接数达到3800时，导致服务器内存和Swap空间用满而崩溃。<br/><br/>　　而这台 Nginx 0.6.31 + PHP 5.2.6 (FastCGI) 服务器在3万并发连接下，开启的10个Nginx进程消耗150M内存（15M*10=150M），开启的64个php-cgi进程消耗1280M内存（20M*64=1280M），加上系统自身消耗的内存，总共消耗不到2GB内存。如果服务器内存较小，完全可以只开启25个php-cgi进程，这样php-cgi消耗的总内存数才500M。<br/><br/>　　在3万并发连接下，访问Nginx 0.6.31 + PHP 5.2.6 (FastCGI) 服务器的PHP程序，仍然速度飞快。下图为Nginx的状态监控页面，显示的活动连接数为28457（关于Nginx的监控页配置，会在本文接下来所给出的Nginx配置文件中写明）：<br/><br/>　　<a href="http://zyan.cc/attachment/200712/nginx_status.png" target="_blank"><img src="http://zyan.cc/attachment/200712/nginx_status.png" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　我生产环境下的两台Nginx + PHP5（FastCGI）服务器，跑多个一般复杂的纯PHP动态程序，单台Nginx + PHP5（FastCGI）服务器跑PHP动态程序的处理能力已经超过“<span style="color: #FF0000;">700次请求/秒</span>”，相当于每天可以承受6000万（700*60*60*24=60480000）的访问量（<a href="read.php/334.htm" target="_blank">更多信息见此</a>），而服务器的系统负载也不算高：<br/><br/>　　<a href="http://zyan.cc/attachment/200803/nginx_php_la.gif" target="_blank"><img src="http://zyan.cc/attachment/200803/nginx_php_la.gif" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/><hr/><br/>　　安装步骤：<br/>　　（系统要求：Linux 2.6+ 内核，本文中的Linux操作系统为CentOS 5.1，另在RedHat AS4上也安装成功）<br/><br/>............<br/><br/>Tags - <a href="http://zyan.cc/tags/linux/" rel="tag">linux</a> , <a href="http://zyan.cc/tags/php/" rel="tag">php</a> , <a href="http://zyan.cc/tags/mysql/" rel="tag">mysql</a> , <a href="http://zyan.cc/tags/nginx/" rel="tag">nginx</a> , <a href="http://zyan.cc/tags/apache/" rel="tag">apache</a> , <a href="http://zyan.cc/tags/centos/" rel="tag">centos</a> , <a href="http://zyan.cc/tags/epoll/" rel="tag">epoll</a> , <a href="http://zyan.cc/tags/fastcgi/" rel="tag">fastcgi</a> , <a href="http://zyan.cc/tags/xcache/" rel="tag">xcache</a> , <a href="http://zyan.cc/tags/httpd/" rel="tag">httpd</a>
]]>
</description>
</item><item>
<link>http://zyan.cc/post/351/#blogcomment1144</link>
<title><![CDATA[[评论] Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>powerv &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 09 Jun 2008 16:13:43 +0000</pubDate> 
<guid>http://zyan.cc/post/351/#blogcomment1144</guid> 
<description>
<![CDATA[ 
	沙发一次，继续支持！有个小疑问 memcache 和Xcache同时用是否会有冲突？
]]>
</description>
</item><item>
<link>http://zyan.cc/post/351/#blogcomment1145</link>
<title><![CDATA[[评论] Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>lphy &lt;lphhy168@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 09 Jun 2008 16:18:54 +0000</pubDate> 
<guid>http://zyan.cc/post/351/#blogcomment1145</guid> 
<description>
<![CDATA[ 
	终于看到新版本了，而且加入了最新的php-fpm和xcache部分～！
]]>
</description>
</item><item>
<link>http://zyan.cc/post/351/#blogcomment1146</link>
<title><![CDATA[[评论] Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>lphy &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 09 Jun 2008 16:58:28 +0000</pubDate> 
<guid>http://zyan.cc/post/351/#blogcomment1146</guid> 
<description>
<![CDATA[ 
	有点小疑问，看你同时装了memcache和xcache，这两个可以一起用吗？如果换成eaccelerator和xcache可以吗？还是memcache和eaccelerator？我目前是nginx+zendoptimizer+eaccelerator(由于有时候要运行zend加密过的文件非得装zendoptimizer)，主要运行discuz，有什么好的建议吗？谢谢～！
]]>
</description>
</item><item>
<link>http://zyan.cc/post/351/#blogcomment1147</link>
<title><![CDATA[[评论] Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>Laurence &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 10 Jun 2008 01:36:23 +0000</pubDate> 
<guid>http://zyan.cc/post/351/#blogcomment1147</guid> 
<description>
<![CDATA[ 
	有没有实测过unix socket和tcp socket的区别?
]]>
</description>
</item><item>
<link>http://zyan.cc/post/351/#blogcomment1148</link>
<title><![CDATA[[评论] Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>linuxtone &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 10 Jun 2008 02:04:40 +0000</pubDate> 
<guid>http://zyan.cc/post/351/#blogcomment1148</guid> 
<description>
<![CDATA[ 
	非常感谢能够分享这么精彩的文章！<br/>转载一下你的章:<a href="http://bbs.linuxtone.org/thread-333-1-1.html" target="_blank">http://bbs.linuxtone.org/thread-333-1-1.html</a>
]]>
</description>
</item><item>
<link>http://zyan.cc/post/351/#blogcomment1149</link>
<title><![CDATA[[评论] Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>yls &lt;yls_4@163.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 10 Jun 2008 04:22:00 +0000</pubDate> 
<guid>http://zyan.cc/post/351/#blogcomment1149</guid> 
<description>
<![CDATA[ 
	我的 mcrypt-2.6.7.tar.gz没有办法编译进去，你这个是86还是X86——64
]]>
</description>
</item><item>
<link>http://zyan.cc/post/351/#blogcomment1150</link>
<title><![CDATA[[评论] Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>lele &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 10 Jun 2008 04:51:45 +0000</pubDate> 
<guid>http://zyan.cc/post/351/#blogcomment1150</guid> 
<description>
<![CDATA[ 
	我的网站在正常运行。不过如果地址输入错误的话打开的是一个这样的页面<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 404 Not Found<br/><br/>--------------------------------------------------------------------------------<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nginx/0.5.35<br/><br/>但是我想定制一个自己的错误页面，或像apache一样<br/><br/>找不到网页 <br/>您要查看的网页可能已被删除、名称已被更改，或者暂时不可用。 <br/><br/>--------------------------------------------------------------------------------<br/><br/>请尝试以下操作:<br/><br/> 请问下这个要怎么搞？
]]>
</description>
</item><item>
<link>http://zyan.cc/post/351/#blogcomment1152</link>
<title><![CDATA[[评论] Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>李杰 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 10 Jun 2008 06:35:17 +0000</pubDate> 
<guid>http://zyan.cc/post/351/#blogcomment1152</guid> 
<description>
<![CDATA[ 
	请教一下播主，现在有没有能与Nginx相结合的*nix虚拟主机管理系统，谢谢。
]]>
</description>
</item><item>
<link>http://zyan.cc/post/351/#blogcomment1153</link>
<title><![CDATA[[评论] Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>lphy &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 10 Jun 2008 06:42:28 +0000</pubDate> 
<guid>http://zyan.cc/post/351/#blogcomment1153</guid> 
<description>
<![CDATA[ 
	感谢这么快就回复，而且回复的这么仔细～！<br/>还有点小疑问，文中的memcache.so是Memcached的客户端PHP扩展的话，那就是要装了Memcached才能起作用了，用Memcached的话是要改php代码的吧？<br/>另外有没有测试过XCache和eaccelerator以及APC哪个好一点？谢谢～！
]]>
</description>
</item><item>
<link>http://zyan.cc/post/351/#blogcomment1154</link>
<title><![CDATA[[评论] Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>chancey &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 10 Jun 2008 07:12:26 +0000</pubDate> 
<guid>http://zyan.cc/post/351/#blogcomment1154</guid> 
<description>
<![CDATA[ 
	Waiting 值为0吗？PHP-FASTCGI能同事处理所有的请求吗？数据库允许吗？
]]>
</description>
</item><item>
<link>http://zyan.cc/post/351/#blogcomment1155</link>
<title><![CDATA[[评论] Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>lele &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 10 Jun 2008 07:56:43 +0000</pubDate> 
<guid>http://zyan.cc/post/351/#blogcomment1155</guid> 
<description>
<![CDATA[ 
	谢谢你的答复，还想问下，error的404.html 这个文件在哪个目录里？我想修改下
]]>
</description>
</item><item>
<link>http://zyan.cc/post/351/#blogcomment1157</link>
<title><![CDATA[[评论] Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>lele &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 10 Jun 2008 08:44:59 +0000</pubDate> 
<guid>http://zyan.cc/post/351/#blogcomment1157</guid> 
<description>
<![CDATA[ 
	我已经修改好了。谢谢
]]>
</description>
</item><item>
<link>http://zyan.cc/post/351/#blogcomment1158</link>
<title><![CDATA[[评论] Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>守住每一天 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 10 Jun 2008 09:39:56 +0000</pubDate> 
<guid>http://zyan.cc/post/351/#blogcomment1158</guid> 
<description>
<![CDATA[ 
	问下：如果再安装zend 是否会有冲突？
]]>
</description>
</item><item>
<link>http://zyan.cc/post/351/#blogcomment1159</link>
<title><![CDATA[[评论] Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>守住每一天 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 10 Jun 2008 09:47:06 +0000</pubDate> 
<guid>http://zyan.cc/post/351/#blogcomment1159</guid> 
<description>
<![CDATA[ 
	php-fpm &nbsp;的具体作用是？<br/>为什么我编译的时候却没有这个参数？<br/><br/>./configure --help &#124;grep fpm &nbsp; 与<br/>./configure --help &#124;grep sysvsem <br/>都没有。<br/><br/>我的环境是:&quot;<br/>centos 5<br/>php 5.2.6
]]>
</description>
</item><item>
<link>http://zyan.cc/post/351/#blogcomment1164</link>
<title><![CDATA[[评论] Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>Sonic &lt;soniccube@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 10 Jun 2008 18:01:31 +0000</pubDate> 
<guid>http://zyan.cc/post/351/#blogcomment1164</guid> 
<description>
<![CDATA[ 
	我想请教一下张老师,nginx是否有办法像apache一样,使用cronolog之类的软件进行日志截断呢?<br/><br/>我自己尝试了一下,好像都没有办法!<br/><br/>时间长了access_log非常大.
]]>
</description>
</item>
</channel>
</rss>