<?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>haohtml&#039;s blog &#187; nginx</title>
	<atom:link href="http://blog.haohtml.com/tag/nginx/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.haohtml.com</link>
	<description>haohtml&#039;s life and works</description>
	<lastBuildDate>Tue, 22 May 2012 04:57:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法</title>
		<link>http://blog.haohtml.com/archives/12842</link>
		<comments>http://blog.haohtml.com/archives/12842#comments</comments>
		<pubDate>Fri, 04 May 2012 16:50:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[服务器类]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://blog.haohtml.com/?p=12842</guid>
		<description><![CDATA[新开了一个vps,装了最新的nginx 1.0.2版本，将原来的虚拟主机配置直接拿过来．用nginx -t 测试语法的时候，发现提示以下警告信息 [root@centos nginx]# ./sbin/nginx -t nginx: [warn] the "log_format" directive may be used only on "http" level in /usr/local/nginx/conf/vhosts/bbs.conf:62 解决办法如下： 将/usr/local/nginx/conf/nginx.conf 里server段里的下面代码移出放到该server段的前面即可。 log_format  access  '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for'; 如果有其的虚拟主机开启了日志，也按上面的要求移出server段放在server段的前面即可。 再/usr/local/nginx/sbin/nginx -t 测试一下，没有warn警告信息了。 [root@centos vhosts]# ../../sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="nginx中stub_status模块的功能" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F6915&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12842">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4023762.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx中stub_status模块的功能</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用Nginx轻松实现开源负载均衡──9 月20日在ChinaUnix技术沙龙上的演讲PPT[原创]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F3213&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12842">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4027562.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用Nginx轻松实现开源负载均衡──9 月20日在ChinaUnix技术沙龙上的演讲PPT[原创]</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Nginx虚拟主机防Webshell完美版(图)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F2306&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12842">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022380.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Nginx虚拟主机防Webshell完美版(图)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx源代码分析" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F6283&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12842">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4026128.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx源代码分析</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>新开了一个vps,装了最新的nginx 1.0.2版本，将原来的虚拟主机配置直接拿过来．用nginx -t 测试语法的时候，发现提示以下警告信息</p>
<blockquote><p>[root@centos nginx]# ./sbin/nginx -t<br />
nginx: [warn] the "log_format" directive may be used only on "http" level in /usr/local/nginx/conf/vhosts/bbs.conf:62</p></blockquote>
<p>解决办法如下：</p>
<p>将/usr/local/nginx/conf/nginx.conf 里server段里的下面代码移出放到该server段的前面即可。</p>
<blockquote><p>log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '<br />
'$status $body_bytes_sent "$http_referer" '<br />
'"$http_user_agent" $http_x_forwarded_for';</p></blockquote>
<p>如果有其的虚拟主机开启了日志，也按上面的要求移出server段放在server段的前面即可。</p>
<p>再<strong>/usr/local/nginx/sbin/nginx -t</strong> 测试一下，没有warn警告信息了。</p>
<blockquote><p>[root@centos vhosts]# ../../sbin/nginx -t<br />
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok<br />
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful<br />
[root@centos vhosts]#</p></blockquote>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="nginx中stub_status模块的功能" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F6915&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12842">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4023762.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx中stub_status模块的功能</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用Nginx轻松实现开源负载均衡──9 月20日在ChinaUnix技术沙龙上的演讲PPT[原创]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F3213&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12842">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4027562.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用Nginx轻松实现开源负载均衡──9 月20日在ChinaUnix技术沙龙上的演讲PPT[原创]</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Nginx虚拟主机防Webshell完美版(图)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F2306&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12842">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022380.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Nginx虚拟主机防Webshell完美版(图)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx源代码分析" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F6283&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12842">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4026128.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx源代码分析</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://blog.haohtml.com/archives/12842/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx 的限制连接模块limit_zone与limit_req_zone</title>
		<link>http://blog.haohtml.com/archives/12640</link>
		<comments>http://blog.haohtml.com/archives/12640#comments</comments>
		<pubDate>Sun, 25 Mar 2012 08:19:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[服务器类]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://blog.haohtml.com/?p=12640</guid>
		<description><![CDATA[nginx 上有两个限制连接的模块一个是 limit_zone 另一个是 limie_req_zone,两个都可以限制连接，但具体有什么不同呢？ 下面是 nginx 官网上给的解释 limit_req_zone Limit frequency of connections from a client. This module allows you to limit the number of requests for a given session, or as a special case, with one address. Restriction done using leaky bucket. limit_zone Limit simultaneous connections from a client. This module makes it possible [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12842&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12640">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用Nginx的proxy_cache缓存功能取代Squid[原创]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F3165&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12640">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4027570.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用Nginx的proxy_cache缓存功能取代Squid[原创]</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Nginx虚拟主机防Webshell完美版(图)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F2306&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12640">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022380.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Nginx虚拟主机防Webshell完美版(图)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="分享一份nginx重启脚本" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1305&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12640">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">分享一份nginx重启脚本</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>nginx 上有两个限制连接的模块一个是 limit_zone 另一个是 limie_req_zone,两个都可以限制连接，但具体有什么不同呢？<br />
下面是 nginx 官网上给的解释</p>
<blockquote><p>limit_req_zone<br />
Limit frequency of connections from a client.<br />
This module allows you to limit the number of requests for a given session, or as a special case, with one address.<br />
Restriction done using leaky bucket.</p>
<p>limit_zone<br />
Limit simultaneous connections from a client.<br />
This module makes it possible to limit the number of simultaneous connections for the assigned session or as a special case, from one address.</p></blockquote>
<p>按照字面的理解，lit_req_zone的功能是通过 令牌桶原理来限制 用户的连接频率，(这个模块允许你去限制单个地址 指定会话或特殊需要 的请求数 )<br />
而 limit_zone 功能是限制一个客户端的并发连接数。(这个模块可以限制单个地址 的指定会话 或者特殊情况的并发连接数)<span id="more-12640"></span><br />
一个是限制并发连接一个是限制连接频率，表面上似乎看不出来有什么区别，那就看看实际的效果吧~~~<br />
在我的测试机上面加上这两个参数下面是我的部分配置文件</p>
<blockquote><p>http{<br />
limit_zone one  $binary_remote_addr  10m;<br />
#limit_req_zone  $binary_remote_addr  zone=req_one:10m rate=1r/s;<br />
server<br />
{<br />
......<br />
limit_conn   one  1;<br />
#limit_req   zone=req_one  burst=120;<br />
......<br />
}<br />
}</p></blockquote>
<p>解释一下 limit_zone one  $binary_remote_addr  10m;<br />
这里的 one 是声明一个 limit_zone 的名字，$binary_remote_addr是替代 $remore_addr 的变量，10m 是会话状态储存的空间<br />
limit_conn one 1 ,限制客户端并发连接数量为1<br />
先测试 limit_zone 这个模块<br />
我找一台机器 用ab 来测试一下 命令格式为</p>
<blockquote><p>ab -c 100 -t 10 http://192.168.6.26/test.php</p></blockquote>
<p>test.php 内容是&lt;?php phpinfo(); ?&gt;<br />
看看日志里的访问</p>
<p><a href="http://img1.51cto.com/attachment/201108/140650433.jpg" target="_blank" rel="lightbox[12640]"><img src="http://img1.51cto.com/attachment/201108/140650433.jpg" alt="" border="0" /></a></p>
<p>看来也不一定能限制的住1秒钟1个并发连接，（有网友跟我说这是因为测试的文件本身太小了才会这样，有时间一定测试一下），从日志里面可以看得出来 除了几个200以外其他的基本都是503，多数并发访问都被503了。</p>
<p>我又用ab多运行了一会儿，发现另一种情况</p>
<p><a href="http://img1.51cto.com/attachment/201108/140727549.jpg" target="_blank" rel="lightbox[12640]"><img src="http://img1.51cto.com/attachment/201108/140727549.jpg" alt="" border="0" /></a></p>
<p>似乎随着数量的增多效果也会发生一些变化，并不是完全达到模块说明中的效果<br />
看看当前的tcp连接数</p>
<blockquote><p># netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'<br />
TIME_WAIT 29<br />
FIN_WAIT1 152<br />
FIN_WAIT2 2<br />
ESTABLISHED 26<br />
SYN_RECV 16</p></blockquote>
<p>这次测试下 limit_req_zone,配置文件稍微改动一下</p>
<blockquote><p>http{<br />
#limit_zone one  $binary_remote_addr  10m;<br />
limit_req_zone  $binary_remote_addr  zone=req_one:10m rate=1r/s;<br />
server<br />
{<br />
......<br />
#limit_conn   one  1;<br />
limit_req   zone=req_one  burst=120;<br />
......<br />
}<br />
}</p></blockquote>
<p>restart 一下 nginx<br />
简单说明一下， rate=1r/s 的意思是每个地址每秒只能请求一次，也就是说根据令牌桶(经过网友冰冰的指正应该是漏桶原理)原理 burst=120 一共有120块令牌，并且每秒钟只新增1块令牌，<br />
120块令牌发完后 多出来的那些请求就会返回503<br />
测试一下</p>
<blockquote><p>ab -c 100 -t 10 http://192.168.6.26/test.php</p></blockquote>
<p>看看这时候的访问日志<a href="http://img1.51cto.com/attachment/201108/141110969.jpg" target="_blank" rel="lightbox[12640]"><br />
</a></p>
<p><a href="http://img1.51cto.com/attachment/201108/142708172.jpg" target="_blank" rel="lightbox[12640]"><img src="http://img1.51cto.com/attachment/201108/142708172.jpg" alt="" border="0" /></a></p>
<p>确实是每秒请求一次，那多测试一会儿呢？把时间从10秒增加到30秒</p>
<p><a href="http://img1.51cto.com/attachment/201108/141151674.jpg" target="_blank" rel="lightbox[12640]"><br />
</a></p>
<p><a href="http://img1.51cto.com/attachment/201108/144303203.jpg" target="_blank" rel="lightbox[12640]"><img src="http://img1.51cto.com/attachment/201108/144303203.jpg" alt="" border="0" /></a></p>
<p>这个时候应该是120 已经不够用了，出现很多503，还有两种情况会出现,请看图</p>
<p><a href="http://img1.51cto.com/attachment/201108/141228407.jpg" target="_blank" rel="lightbox[12640]"><img src="http://img1.51cto.com/attachment/201108/141228407.jpg" alt="" border="0" /></a></p>
<p>这种情况很像是 在队列里的一些请求得不到响应而超时了，但我不确定是不是这种情况。</p>
<p><a href="http://img1.51cto.com/attachment/201108/141251535.jpg" target="_blank" rel="lightbox[12640]"><img src="http://img1.51cto.com/attachment/201108/141251535.jpg" alt="" border="0" /></a></p>
<p>客户端自己等不及断开了，返回499<br />
看看当前的tcp连接数</p>
<blockquote><p>netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'<br />
TIME_WAIT 51<br />
FIN_WAIT1 5<br />
ESTABLISHED 155<br />
SYN_RECV 12</p></blockquote>
<p>虽然这样会让nginx 一秒钟只处理一个请求，但是仍然会有很多还在队列里面等待处理，这样也会占用很多tcp连接，从上面那条命令的结果中就能看得出来。<br />
如果这样呢</p>
<blockquote><p>limit_req   zone=req_one  burst=120 nodelay;</p></blockquote>
<p>加上 nodelay之后超过 burst大小的请求就会直接 返回503，如图</p>
<p><a href="http://img1.51cto.com/attachment/201108/141406358.jpg" target="_blank" rel="lightbox[12640]"><img src="http://img1.51cto.com/attachment/201108/141406358.jpg" alt="" border="0" /></a></p>
<p>也是每秒处理1个请求，但多出来的请求没有象刚才那样等待处理，而是直接返回503。</p>
<p>当前的tcp连接</p>
<blockquote><p># netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'<br />
TIME_WAIT 30<br />
FIN_WAIT1 15<br />
SYN_SENT 7<br />
FIN_WAIT2 1<br />
ESTABLISHED 40<br />
SYN_RECV 37</p></blockquote>
<p>已连接的数量比上面的少了一些<br />
通过这次测试我发现 这两种模块都不能做到绝对的限制，但的确已经起到了很大的减少并发和限制连接的作用，在生产环境中具体用哪种或者需要两种在一起使用就要看各自的需求了。<br />
测试就到这里，如果文章里有不对的地方请大家及时指正，谢谢</p>
<p>本文出自 “<a href="http://storysky.blog.51cto.com/">story的天空</a>” 博客，请务必保留此出处<a href="http://storysky.blog.51cto.com/628458/642970">http://storysky.blog.51cto.com/628458/642970</a></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12842&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12640">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用Nginx的proxy_cache缓存功能取代Squid[原创]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F3165&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12640">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4027570.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用Nginx的proxy_cache缓存功能取代Squid[原创]</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Nginx虚拟主机防Webshell完美版(图)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F2306&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12640">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022380.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Nginx虚拟主机防Webshell完美版(图)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="分享一份nginx重启脚本" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1305&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12640">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">分享一份nginx重启脚本</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://blog.haohtml.com/archives/12640/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如何安装nginx的第三方模块</title>
		<link>http://blog.haohtml.com/archives/12349</link>
		<comments>http://blog.haohtml.com/archives/12349#comments</comments>
		<pubDate>Wed, 28 Dec 2011 08:51:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[服务器类]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://blog.haohtml.com/?p=12349</guid>
		<description><![CDATA[明天晚上一口气将agentzh写的"Nginx变量漫谈1-8"看完了.于是手动测试一下这些第三方模块. 这里以HttpEchoModule模块为例. 由于以前安装过nginx,所以这里重新configure一下.并且指定新添加的模块路径.使用--add-module=/path/to/module_name指令.可以参考:http://wiki.nginx.org/HttpEchoModule#Installation 这里只指定了一个HttpEchoModule这个模块.模块下载地址见:https://github.com/agentzh/echo-nginx-module/tags,如果有多个模块的话,只需要多次使用-add-module指令即可. 先下载HttpEchoModule模块 cd /usr/src/soft/nginx-1.1.1/ mkdir module cd module wget "https://github.com/agentzh/echo-nginx-module/tarball/v0.37rc7" tar zxvf v0.37rc7 重新配置加入第三方模块 cd /usr/src/soft/nginx-1.1.1 ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/usr/src/soft/nginx-1.1.1/module/agentzh-echo-nginx-module-b7ea185/ make &#38;&#38; make install 现在新模块已经安装成功.可以使用下面的方法进行测试 server { listen 8080; location /test { set $foo hello; echo "foo: $foo"; } } 启动Nginx服务 /usr/local/nginx/sbin/nginx 用curl命令测试 [root@bogon nginx-1.1.1]# curl http://localhost:8080/test foo: hello [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Nginx虚拟主机防Webshell完美版(图)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F2306&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12349">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022380.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Nginx虚拟主机防Webshell完美版(图)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx 的限制连接模块limit_zone与limit_req_zone" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12640&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12349">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/03/25/18120978.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx 的限制连接模块limit_zone与limit_req_zone</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="新型的大型bbs架构（squid+nginx）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F3784&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12349">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4026262.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">新型的大型bbs架构（squid+nginx）</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用Nginx的proxy_cache缓存功能取代Squid[原创]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F3165&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12349">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4027570.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用Nginx的proxy_cache缓存功能取代Squid[原创]</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>明天晚上一口气将agentzh写的"<a href="http://blog.sina.com.cn/s/blog_6d579ff40100xm7t.html" target="_blank">Nginx变量漫谈1-8</a>"看完了.于是手动测试一下这些第三方模块.</p>
<p>这里以HttpEchoModule模块为例.</p>
<p>由于以前安装过nginx,所以这里重新configure一下.并且指定新添加的模块路径.使用--add-module=/path/to/module_name指令.可以参考:<a href="http://wiki.nginx.org/HttpEchoModule#Installation">http://wiki.nginx.org/HttpEchoModule#Installation</a></p>
<p>这里只指定了一个HttpEchoModule这个模块.模块下载地址见:<a href="https://github.com/agentzh/echo-nginx-module/tags">https://github.com/agentzh/echo-nginx-module/tags</a>,如果有多个模块的话,只需要多次使用-add-module指令即可.</p>
<p>先下载HttpEchoModule模块</p>
<pre class="brush:[shell]">cd /usr/src/soft/nginx-1.1.1/
mkdir module
cd module
wget "https://github.com/agentzh/echo-nginx-module/tarball/v0.37rc7"
tar zxvf v0.37rc7</pre>
<p><span id="more-12349"></span>重新配置加入第三方模块</p>
<pre class="brush:[shell]">cd /usr/src/soft/nginx-1.1.1
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/usr/src/soft/nginx-1.1.1/module/agentzh-echo-nginx-module-b7ea185/
make &amp;&amp; make install</pre>
<pre>现在新模块已经安装成功.可以使用下面的方法进行测试</pre>
<blockquote>
<pre>server {
    listen 8080;
        location /test {
        set $foo hello;
        echo "foo: $foo";
    }
}</pre>
</blockquote>
<p>启动Nginx服务</p>
<pre class="brush:[shell]">/usr/local/nginx/sbin/nginx</pre>
<p>用curl命令测试</p>
<pre class="brush:[shell]">[root@bogon nginx-1.1.1]# curl http://localhost:8080/test
foo: hello</pre>
<p>更多第三方模块也可以参考:<a href="http://chenxiaoyu.org/2011/10/30/nginx-modules.html" target="_blank">http://chenxiaoyu.org/2011/10/30/nginx-modules.html</a></p>
<p>&nbsp;</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Nginx虚拟主机防Webshell完美版(图)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F2306&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12349">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022380.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Nginx虚拟主机防Webshell完美版(图)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx 的限制连接模块limit_zone与limit_req_zone" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12640&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12349">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/03/25/18120978.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx 的限制连接模块limit_zone与limit_req_zone</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="新型的大型bbs架构（squid+nginx）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F3784&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12349">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4026262.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">新型的大型bbs架构（squid+nginx）</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用Nginx的proxy_cache缓存功能取代Squid[原创]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F3165&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12349">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4027570.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用Nginx的proxy_cache缓存功能取代Squid[原创]</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://blog.haohtml.com/archives/12349/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>章亦春：nginx的http服务器&amp;套Web应用开发框架</title>
		<link>http://blog.haohtml.com/archives/12130</link>
		<comments>http://blog.haohtml.com/archives/12130#comments</comments>
		<pubDate>Thu, 24 Nov 2011 11:11:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[服务器类]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://blog.haohtml.com/?p=12130</guid>
		<description><![CDATA[<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="[推荐]nginx配置文件的优化-关于nginx的一些优化(突破十万并发)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F6925&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12130">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4023760.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">[推荐]nginx配置文件的优化-关于nginx的一些优化(突破十万并发)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx 的限制连接模块limit_zone与limit_req_zone" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12640&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12130">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/03/25/18120978.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx 的限制连接模块limit_zone与limit_req_zone</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx图片服务器的架构方案[2009-03-18 01:15:06]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1363&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12130">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022398.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx图片服务器的架构方案[2009-03-18 01:15:06]</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用Nginx的proxy_cache缓存功能取代Squid[原创]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F3165&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12130">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4027570.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用Nginx的proxy_cache缓存功能取代Squid[原创]</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p><script data-vid="D00rqtnRwKzJdIsB" src="//player.ku6.com/out/v.js" data-width="480" data-height="400"></script></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="[推荐]nginx配置文件的优化-关于nginx的一些优化(突破十万并发)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F6925&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12130">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4023760.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">[推荐]nginx配置文件的优化-关于nginx的一些优化(突破十万并发)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx 的限制连接模块limit_zone与limit_req_zone" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12640&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12130">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/03/25/18120978.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx 的限制连接模块limit_zone与limit_req_zone</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx图片服务器的架构方案[2009-03-18 01:15:06]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1363&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12130">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022398.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx图片服务器的架构方案[2009-03-18 01:15:06]</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用Nginx的proxy_cache缓存功能取代Squid[原创]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F3165&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12130">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4027570.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用Nginx的proxy_cache缓存功能取代Squid[原创]</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://blog.haohtml.com/archives/12130/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx作为反向代理时传递客户端IP</title>
		<link>http://blog.haohtml.com/archives/11434</link>
		<comments>http://blog.haohtml.com/archives/11434#comments</comments>
		<pubDate>Wed, 14 Sep 2011 00:46:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[系统架构]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[反向代理]]></category>

		<guid isPermaLink="false">http://blog.haohtml.com/?p=11434</guid>
		<description><![CDATA[因为架构的需要采用多级 Nginx 反向代理，但是后端的程序获取到的客户端 IP 都是前端 Nginx 的 IP，问题的根源在于后端的 Nginx 在 HTTP Header 中取客户端 IP 时没有取对正确的值。同样适用于前端是 Squid 或者其他反向代理的情况。（通用的解决方案是直接取服务器的变量　HTTP_X_FORWARDED_FOR　的值即可取出客户端的真实ip地址） 首先前端的 Nginx 要做转发客户端 IP 的配置： location / { proxy_pass        http://localhost:8000;# Forward the user's IP address to Rails proxy_set_header           X-Real-IP $remote_addr; # needed for HTTPS #  proxy_set_header         [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="利用 squid 反向代理提高网站性能" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1383&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11434">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/14/5576191.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">利用 squid 反向代理提高网站性能</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="反向代理简介" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1378&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11434">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4027547.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">反向代理简介</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="搭建一个大型网站架构的实验环境(Nginx代理服务器篇)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F937&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11434">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022461.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">搭建一个大型网站架构的实验环境(Nginx代理服务器篇)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="freebsd7.0 apache php squid 反向代理" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F944&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11434">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4026062.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">freebsd7.0 apache php squid 反向代理</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>因为架构的需要采用多级 Nginx 反向代理，但是后端的程序获取到的客户端 IP 都是前端 Nginx 的 IP，问题的根源在于后端的 Nginx 在 HTTP Header 中取客户端 IP 时没有取对正确的值。同样适用于前端是 Squid 或者其他反向代理的情况。（通用的解决方案是直接取服务器的变量　HTTP_X_FORWARDED_FOR　的值即可取出客户端的真实ip地址）</p>
<p>首先前端的 Nginx 要做转发客户端 IP 的配置：</p>
<div>
<blockquote>
<div>location / {<br />
proxy_pass        http://localhost:8000;# Forward the user's IP address to Rails<br />
proxy_set_header           X-Real-IP $remote_addr;<br />
# needed for HTTPS<br />
#  proxy_set_header           X_FORWARDED_PROTO https;<br />
proxy_set_header           X-Forwarded-For $remote_addr;<br />
proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;<br />
proxy_set_header           Host $host;<br />
proxy_redirect                off;<br />
}</div>
</blockquote>
</div>
<p>后端的 Nginx 需要安装一个 Module： <a href="http://wiki.nginx.org/NginxHttpRealIpModule">NginxHttpRealIpModule</a> ，编译的时候默认不包含此 Module，需要重新编译安装 Nginx，configure 的时候加上 –with-http_realip_module，Nginx 升级或者添加/删除 Module 时支持<a href="http://www.sonitech.org/2010/05/20/nginx-notes-tips/">热切换</a> ，可以避免中断服务。<span id="more-11434"></span></p>
<p>升级后配置 NginxHttpRealIpModule，set_real_ip_from 就是指前端 Nginx 或者 Squid 的 IP：</p>
<div>
<div>location / {<br />
proxy_pass        http://localhost:8000;# Forward the user's IP address to Rails<br />
<span style="color: #0000ff;">  proxy_set_header           X-Real-IP $remote_addr;</span><br />
# needed for HTTPS<br />
#  proxy_set_header           X_FORWARDED_PROTO https;<br />
<span style="color: #0000ff;">  proxy_set_header           X-Forwarded-For $remote_addr;</span><br />
<span style="color: #0000ff;">  proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;</span><br />
<span style="color: #0000ff;">  proxy_set_header           Host $host;</span><br />
<span style="color: #0000ff;">  proxy_redirect                off;</span><br />
<span style="color: #ff6600;"># NginxHttpRealIpModule</span><br />
<span style="color: #0000ff;">  set_real_ip_from   192.168.1.0/24;</span><br />
<span style="color: #0000ff;">  set_real_ip_from   192.168.2.1;</span><br />
<span style="color: #0000ff;">  real_ip_header     X-Real-IP;</span><br />
}</div>
</div>
<p>最后记得 reload Nginx config.使nginx平滑过渡，应用新的配置文件．</p>
<p>===================================</p>
<p>另也有网友给的以下方法，和上面的差不多，但不需要其它的模块，只是在取ip的时候，取的服务器变量有些不一样．由于程序修改度小，所以此方法用的较多．</p>
<p>在nginx中设置:</p>
<blockquote><p>proxy_set_header        Host            $host;<br />
proxy_set_header        X-Real-IP       $remote_addr;<br />
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;</p></blockquote>
<p>后端程序可以从Server变量 <span style="color: #0000ff;"><strong>HTTP_X_REAL_IP </strong></span>和 <span style="color: #0000ff;"><strong>HTTP_X_FORWARDED_FOR </strong></span>中获取用户的ip地址。</p>
<p>HTTP_X_REAL_IP的值是nginx得到的用户REMOTE_ADDR</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="利用 squid 反向代理提高网站性能" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1383&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11434">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/14/5576191.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">利用 squid 反向代理提高网站性能</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="反向代理简介" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1378&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11434">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4027547.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">反向代理简介</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="搭建一个大型网站架构的实验环境(Nginx代理服务器篇)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F937&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11434">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022461.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">搭建一个大型网站架构的实验环境(Nginx代理服务器篇)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="freebsd7.0 apache php squid 反向代理" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F944&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11434">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4026062.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">freebsd7.0 apache php squid 反向代理</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://blog.haohtml.com/archives/11434/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx中的gzip模块简介</title>
		<link>http://blog.haohtml.com/archives/11211</link>
		<comments>http://blog.haohtml.com/archives/11211#comments</comments>
		<pubDate>Fri, 02 Sep 2011 09:46:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[服务器类]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://blog.haohtml.com/?p=11211</guid>
		<description><![CDATA[gzip 语法: gzip on&#124;off 默认值: gzip off 作用域: http, server, location, if (x) location 开启或者关闭gzip模块 &#160; gzip_buffers 语法: gzip_buffers number size 默认值: gzip_buffers 4 4k/8k 作用域: http, server, location 设置系统获取几个单位的缓存用于存储gzip的压缩结果数据流。例如 4 4k 代表以4k为单位，按照原始数据大小以4k为单位的4倍申请内存。 4 8k 代表以8k为单位，按照原始数据大小以8k为单位的4倍申请内存。 如果没有设置，默认值是申请跟原始数据相同大小的内存空间去存储gzip压缩结果。 &#160; gzip_comp_level 语法: gzip_comp_level 1..9 默认值: gzip_comp_level 1 作用域: http, server, location gzip压缩比，1 压缩比最小处理速度最快，9 压缩比最大但处理最慢（传输快但比较消耗cpu）。 &#160; gzip_min_length 语法: [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12842&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11211">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx源代码分析" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F6283&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11211">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4026128.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx源代码分析</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx图片服务器的架构方案[2009-03-18 01:15:06]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1363&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11211">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022398.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx图片服务器的架构方案[2009-03-18 01:15:06]</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Nginx无缝升级教程" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11025&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11211">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Nginx无缝升级教程</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<h2>gzip</h2>
<p><strong>语法:</strong> <em>gzip on|off</em></p>
<p><strong>默认值:</strong> <em>gzip off</em></p>
<p><strong>作用域:</strong> <em>http, server, location, if (x) location</em></p>
<p>开启或者关闭gzip模块</p>
<p>&nbsp;</p>
<h2>gzip_buffers</h2>
<p><strong>语法:</strong> <em>gzip_buffers number size</em></p>
<p><strong>默认值:</strong> <em>gzip_buffers 4 4k/8k</em></p>
<p><strong>作用域:</strong> <em>http, server, location</em><br />
设置系统获取几个单位的缓存用于存储gzip的压缩结果数据流。例如 4 4k 代表以4k为单位，按照原始数据大小以4k为单位的4倍申请内存。 4 8k 代表以8k为单位，按照原始数据大小以8k为单位的4倍申请内存。<span id="more-11211"></span></p>
<p>如果没有设置，默认值是申请跟原始数据相同大小的内存空间去存储gzip压缩结果。</p>
<p>&nbsp;</p>
<h2><strong>gzip_comp_level</strong></h2>
<p><strong>语法:</strong> <em><strong>gzip_comp_level</strong> 1..9</em></p>
<p><strong>默认值:</strong> <em><strong>gzip_comp_level</strong> 1</em></p>
<p><strong>作用域:</strong> <em>http, server, location</em></p>
<p>gzip压缩比，1 压缩比最小处理速度最快，9 压缩比最大但处理最慢（传输快但比较消耗cpu）。</p>
<p>&nbsp;</p>
<h2>gzip_min_length</h2>
<p><strong>语法:</strong> <em>gzip_min_length length</em></p>
<p><strong>默认值:</strong> <em>gzip_min_length 0</em></p>
<p><strong>作用域:</strong> <em>http, server, location</em><br />
设置允许压缩的页面最小字节数，页面字节数从header头中的Content-Length中进行获取。</p>
<p>默认值是0，不管页面多大都压缩。</p>
<p>建议设置成大于1k的字节数，小于1k可能会越压越大。即: gzip_min_length 1024</p>
<p>&nbsp;</p>
<h2>gzip_http_version</h2>
<p><strong>语法:</strong> <em>gzip_http_version 1.0|1.1</em></p>
<p><strong>默认值:</strong> <em>gzip_http_version 1.1</em></p>
<p><strong>作用域:</strong> <em>http, server, location</em></p>
<p>识别http的协议版本。由于早期的一些浏览器或者http客户端，可能不支持gzip自解压，用户就会看到乱码，所以做一些判断还是有必要的。 注：21世纪都来了，现在除了类似于百度的蜘蛛之类的东西不支持自解压，99.99%的浏览器基本上都支持gzip解压了，所以可以不用设这个值,保持系 统默认即可。</p>
<p>&nbsp;</p>
<h2>gzip_proxied</h2>
<p><strong>语法:</strong> <em>gzip_proxied [off|expired|no-cache|no-store|private|no_last_modified|no_etag|auth|any] ...</em></p>
<p><strong>默认值:</strong> <em>gzip_proxied off</em></p>
<p><strong>作用域:</strong> <em>http, server, location</em></p>
<p>Nginx作为反向代理的时候启用，开启或者关闭后端服务器返回的结果，匹配的前提是后端服务器必须要返回包含"Via"的 header头。</p>
<ul>
<li>off - 关闭所有的代理结果数据的压缩</li>
<li>expired - 启用压缩，如果header头中包含 "Expires" 头信息</li>
<li>no-cache - 启用压缩，如果header头中包含 "Cache-Control:no-cache" 头信息</li>
<li>no-store - 启用压缩，如果header头中包含 "Cache-Control:no-store" 头信息</li>
<li>private - 启用压缩，如果header头中包含 "Cache-Control:private" 头信息</li>
<li>no_last_modified - 启用压缩,如果header头中不包含 "Last-Modified" 头信息</li>
<li>no_etag - 启用压缩 ,如果header头中不包含 "ETag" 头信息</li>
<li>auth - 启用压缩 , 如果header头中包含 "Authorization" 头信息</li>
<li>any - 无条件启用压缩</li>
</ul>
<p>&nbsp;</p>
<h2>gzip_types</h2>
<p><strong>语法:</strong> <em>gzip_types mime-type [mime-type ...] </em></p>
<p><strong>默认值:</strong> <em>gzip_types text/html</em></p>
<p><strong>作用域:</strong> <em>http, server, location</em></p>
<p>匹配MIME类型进行压缩，（无论是否指定）"text/html"类型总是会被压缩的。<br />
注意：如果作为http server来使用，主配置文件中要包含文件类型配置文件</p>
<pre>http
{
 include       conf/mime.types;
 ......
}</pre>
<p>如果你希望压缩常规的文件类型，可以写成这个样子</p>
<pre>http
{
: include       conf/mime.types;

: gzip on;
: gzip_min_length  1000;
: gzip_buffers     4 8k;
: gzip_http_version 1.1;
: gzip_types       application/x-javascript text/css application/xml;

: ......
}</pre>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12842&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11211">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx源代码分析" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F6283&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11211">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4026128.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx源代码分析</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx图片服务器的架构方案[2009-03-18 01:15:06]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1363&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11211">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022398.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx图片服务器的架构方案[2009-03-18 01:15:06]</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Nginx无缝升级教程" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11025&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11211">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Nginx无缝升级教程</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://blog.haohtml.com/archives/11211/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP-FPM高负载的解决办法</title>
		<link>http://blog.haohtml.com/archives/11162</link>
		<comments>http://blog.haohtml.com/archives/11162#comments</comments>
		<pubDate>Fri, 02 Sep 2011 01:07:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[js框架]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php-fpm]]></category>

		<guid isPermaLink="false">http://blog.haohtml.com/?p=11162</guid>
		<description><![CDATA[这里只是介绍了php-fpm的优化方法的，但一般情况下和nginx组合使用的时候，单独优化其中一项的话，作用不是特别的大，同时还需要对nginx进行优化．nginx的做法方法参考：http://blog.haohtml.com/archives/6213.上面的优化前和优化后的图，看得出前后差距还是特别的大的． 导致nginx 502 bad gateway的PHP-CGI(FASTCGI) NGINX频爆502 BAD GATEWAY的错误，看了网上的教程，仍没有彻底解决。 目前我总结的解决502 BAD GATEWAY的方式有： 1.视服务器的性能，在php-fmp.conf里增加max_children的值，我目前用的15. 2.用reload参数定时重载php-fpm。这个主要原因是php脚本执行时间过长造成的，重载php-fpm能杜绝这个问题。如何彻底解决php-cgi脚本占用大量内存从而导致502错误的产生还值得进一步探讨，目前该做法不失为一种好办法。 具体的做法是，用crontab让php-fpm平滑重启，从而不影响PHP脚本的运行。 */10 * * * * /usr/local/php/sbin/php-fpm reload ＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝　优化设置 ＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝ When you running a highload website with PHP-FPM via FastCGI, the following tips may be useful to you : ) 如果您高负载网站使用PHP-FPM管理FastCGI，这些技巧也许对您有用：) 1. Compile PHP’s modules as less as possible, the simple the best (fast); [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="nginx php-fpm性能优化设置" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F9280&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11162">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/17/5758359.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx php-fpm性能优化设置</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx下php-fpm详解" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F9283&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11162">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx下php-fpm详解</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="化NGINX+php-fpm上传" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F9275&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11162">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">化NGINX+php-fpm上传</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx下关于PHP-FPM在高负载下的优化配置" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F9292&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11162">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx下关于PHP-FPM在高负载下的优化配置</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>这里只是介绍了php-fpm的优化方法的，但一般情况下和nginx组合使用的时候，单独优化其中一项的话，作用不是特别的大，同时还需要对nginx进行优化．nginx的做法方法参考：<a href="http://blog.haohtml.com/archives/6213">http://blog.haohtml.com/archives/6213</a>.上面的优化前和优化后的图，看得出前后差距还是特别的大的．</p>
<p><span class="Apple-style-span" style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px;">导致<span class="wp_keywordlink_affiliate" style="padding: 0px; margin: 0px;"><a style="color: #015f91; text-decoration: none; padding: 0px; margin: 0px;" title="View all posts in nginx 502 bad gateway" href="http://www.hebaodans.com/tag/nginx-502-bad-gateway/" target="_blank"><span style="color: #2970a6; padding: 0px; margin: 0px;">nginx 502 bad gateway</span></a></span>的PHP-CGI(FASTCGI) </span></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; text-align: left; margin: 0px;">NGINX频爆502 BAD GATEWAY的错误，看了网上的教程，仍没有彻底解决。<br style="padding: 0px; margin: 0px;" /><br />
目前我总结的解决502 BAD GATEWAY的方式有：<br style="padding: 0px; margin: 0px;" /><br />
1.视服务器的性能，在php-fmp.conf里增加max_children的值，我目前用的15.<br style="padding: 0px; margin: 0px;" /><br />
2.用reload参数定时重载php-fpm。这个主要原因是php脚本执行时间过长造成的，重载php-fpm能杜绝这个问题。如何彻底解决php-cgi脚本占用大量内存从而导致502错误的产生还值得进一步探讨，目前该做法不失为一种好办法。<br style="padding: 0px; margin: 0px;" /><span id="more-11162"></span><br />
具体的做法是，用crontab让php-fpm平滑重启，从而不影响PHP脚本的运行。</p>
<blockquote>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; text-align: left; margin: 0px;">*/10 * * * * /usr/local/php/sbin/php-fpm reload</p>
</blockquote>
<p>＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝　优化设置 ＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; text-align: left; margin: 0px;"><span class="Apple-style-span" style="color: #808080;"><br />
When you running a highload website with <span style="padding: 0px; margin: 0px;">PHP-FPM</span> via FastCGI, the following tips may be useful to you : )</span></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; text-align: left; margin: 0px;"><span style="color: #00008b; padding: 0px; margin: 0px;">如果您高负载网站使用<span style="padding: 0px; margin: 0px;">PHP-FPM</span>管理FastCGI，这些技巧也许对您有用：)</span></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin: 0px;"><strong><span style="color: gray; padding: 0px; margin: 0px;">1. Compile PHP’s modules as less as possible, the simple the best (fast);</span></strong><br style="padding: 0px; margin: 0px;" /><br />
<span style="color: #00008b; padding: 0px; margin: 0px;">1.尽量少安装PHP模块，最简单是最好（快）的</span></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin: 0px;">
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin: 0px;"><strong><span class="Apple-style-span" style="color: #808080;">2. Increas PHP FastCGI child number to 100 and even more. Sometime, 200 is OK! ( On 4GB memory server);</span></strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin: 0px;"><span style="color: #00008b; padding: 0px; margin: 0px;">2.把您的PHP FastCGI子进程数调到100或以上，在4G内存的服务器上200就可以</span><br style="padding: 0px; margin: 0px;" /><br />
<span style="color: #4b0082; padding: 0px; margin: 0px;">注：我的1g测试机，开64个是最好的，建议使用压力测试获取最佳值</span></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin: 0px;"><strong><span style="color: gray; padding: 0px; margin: 0px;">3. Using SOCKET PHP FastCGI, and put into /dev/shm on Linux;</span></strong><br style="padding: 0px; margin: 0px;" /><br />
<span style="color: #00008b; padding: 0px; margin: 0px;">3.使用socket连接FastCGI，linux操作系统可以放在 /dev/shm中</span><br style="padding: 0px; margin: 0px;" /><br />
<span style="color: #4b0082; padding: 0px; margin: 0px;">注：在<span style="padding: 0px; margin: 0px;">php-fpm</span>.cnf里设置&lt;value name=”listen_address”&gt;/tmp/nginx.socket&lt;/value&gt;就可以通过socket连接FastCGI了，/dev/shm是内存文件系统，放在内存中肯定会快了.记得这时也要在nginx里的配置里进行修改，保持一致．</span></p>
<blockquote>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin: 0px;"><span style="color: #4b0082; padding: 0px; margin: 0px;">location ~ .*\.(php|php5)?$<br />
{<br />
#将Nginx与FastCGI的通信方式由TCP改为Unix Socket。TCP在高并发访问下比Unix Socket稳定，但Unix Socket速度要比TCP快。<br />
fastcgi_pass  unix:/tmp/php-cgi.sock;<br />
#fastcgi_pass  127.0.0.1:9000;<br />
fastcgi_index index.php;<br />
include fcgi.conf;<br />
}</span></p>
</blockquote>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin: 0px;"><strong><span class="Apple-style-span" style="color: #808080;">4. Increase Linux “max open files”, using the following command (must be root):</span></strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin: 0px;"><span style="color: gray; padding: 0px; margin: 0px;"># echo ‘ulimit -HSn 65536′ &gt;&gt; /etc/profile<br style="padding: 0px; margin: 0px;" /> # echo ‘ulimit -HSn 65536 &gt;&gt; /etc/rc.local<br style="padding: 0px; margin: 0px;" /> # source /etc/profile </span><br style="padding: 0px; margin: 0px;" /><br />
<span style="color: #00008b; padding: 0px; margin: 0px;">4.调高linux内核打开文件数量，可以使用这些命令(必须是root帐号)<br style="padding: 0px; margin: 0px;" /><br />
echo ‘ulimit -HSn 65536′ &gt;&gt; /etc/profile<br style="padding: 0px; margin: 0px;" /> echo ‘ulimit -HSn 65536′ &gt;&gt; /etc/rc.local<br style="padding: 0px; margin: 0px;" /> source /etc/profile </span><br style="padding: 0px; margin: 0px;" /><br />
<span style="color: #4b0082; padding: 0px; margin: 0px;">注：我是修改/etc/rc.local，加入ulimit -SHn 51200的</span></p>
<p><span style="color: gray; padding: 0px; margin: 0px;"><strong>5. Increase <span style="padding: 0px; margin: 0px;">PHP-FPM</span> open file description rlimit:</strong><br style="padding: 0px; margin: 0px;" /><br />
# vi /path/to/<span style="padding: 0px; margin: 0px;">php-fpm</span>.conf<br style="padding: 0px; margin: 0px;" /> Find “&lt;value name=”rlimit_files”&gt;1024&lt;/value&gt;”<br style="padding: 0px; margin: 0px;" /> Change 1024 to 4096 or higher number.<br style="padding: 0px; margin: 0px;" /> Restart <span style="padding: 0px; margin: 0px;">PHP-FPM</span>.</span><br style="padding: 0px; margin: 0px;" /><br />
<span style="color: #00008b; padding: 0px; margin: 0px;">5. 增加 <span style="padding: 0px; margin: 0px;">PHP-FPM</span> 打开文件描述符的限制:<br style="padding: 0px; margin: 0px;" /><br />
# vi /path/to/<span style="padding: 0px; margin: 0px;">php-fpm</span>.conf<br style="padding: 0px; margin: 0px;" /> 找到“&lt;value name=”rlimit_files”&gt;1024&lt;/value&gt;”<br style="padding: 0px; margin: 0px;" /> 把1024 更改为 4096 或者更高.<br />
重启 PHP-FPM.</span></p>
<p><span style="color: #00008b;"><br />
</span> <strong><span style="color: gray; padding: 0px; margin: 0px;">6. Using PHP code accelerator, e.g eAccelerator, XCache. And set “cache_dir” to /dev/shm on Linux.</span></strong><br />
<span style="color: #00008b; padding: 0px; margin: 0px;">6.使用php代码加速器，例如 eAccelerator, XCache.在linux平台上可以把`cache_dir`指向 /dev/shm</span></p>
<p>至于其它的优化见李宴的blog一篇文章：<a href="http://blog.s135.com/post/375/">http://blog.s135.com/post/375/</a></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="nginx php-fpm性能优化设置" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F9280&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11162">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/17/5758359.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx php-fpm性能优化设置</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx下php-fpm详解" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F9283&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11162">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx下php-fpm详解</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="化NGINX+php-fpm上传" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F9275&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11162">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">化NGINX+php-fpm上传</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx下关于PHP-FPM在高负载下的优化配置" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F9292&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11162">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx下关于PHP-FPM在高负载下的优化配置</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://blog.haohtml.com/archives/11162/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Linux(nginx)下安装awstats日志分析软件</title>
		<link>http://blog.haohtml.com/archives/11129</link>
		<comments>http://blog.haohtml.com/archives/11129#comments</comments>
		<pubDate>Thu, 01 Sep 2011 09:24:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[服务器类]]></category>
		<category><![CDATA[awstats]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://blog.haohtml.com/?p=11129</guid>
		<description><![CDATA[这里用的是centos的系统，linux上的安装方法基本上都一样的． 一．下载awstats软件 从http://sourceforge.net/projects/awstats/地址可以下载，这里使用的是最新的7.0的版本 #cd /usr/local #wget http://cdnetworks-kr-1.dl.sourceforge.net/project/awstats/AWStats/7.0/awstats-7.0.zip #unzip awstats-7.0.zip awstats #chmod +x /usr/local/awstats/tools/awstats_configure.pl #chmod +x /usr/local/awstats/wwwroot/cgi-bin/awstats.pl #chmod +x /usr/local/awstats/tools/awstats_buildstaticpages.pl #用来存放swstats的数据文件 #mkdir /var/lib/awstats 二．创建配置文件 #cd /usr/local/awstats/tools/ #perl ./awstats_configure.pl 根据提示信息进行相应的操作即可．好像第一步让输入web的配置文件，由于这里用的是nginx．不是apache的．所以输入none跳过即可． 在后面提示的域名里我们输入我们要分析的域名，如www.haohtml.com 这里会自动创建/etc/awstats/awstats.www.haohtml.com.conf配置文件．里面有些日志文件的路径我们需要修改为实际日志的路径即可．还有日志的默认格式的，要写成 LogFormat="%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot" 这种格式才可以的． 我这里web的日志位置在/var/log/httpd/haohtml/access.log 三．配置Nginx 为了方便，我们直接以独立域名的形式访问，如http://awstats.haohtml.com 配置如下： server { server_name  awstats.haohtml.com; charset gb2312; ...... root   /data/wwwroot/awstats; access_log /var/log/httpd/haohtml/access.log; #这里将日志关闭 access_log off; } 重启Nginx，便虚拟主机配置生效．如果对虚拟主机配置不懂的话，可以参考：http://blog.haohtml.com/archives/6203 [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="使用 awstats 分析 Nginx 的访问日志" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F7068&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11129">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用 awstats 分析 Nginx 的访问日志</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="安装awstats来分析apache的访问日志" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F675&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11129">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4023171.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">安装awstats来分析apache的访问日志</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12842&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11129">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用Nginx的proxy_cache缓存功能取代Squid[原创]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F3165&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11129">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4027570.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用Nginx的proxy_cache缓存功能取代Squid[原创]</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>这里用的是centos的系统，linux上的安装方法基本上都一样的．</p>
<p><strong>一．下载awstats软件</strong></p>
<p>从<a href="http://sourceforge.net/projects/awstats/">http://sourceforge.net/projects/awstats/</a>地址可以下载，这里使用的是最新的7.0的版本</p>
<blockquote><p>#cd /usr/local<br />
#wget <a href="http://cdnetworks-kr-1.dl.sourceforge.net/project/awstats/AWStats/7.0/awstats-7.0.zip" target="_blank">http://cdnetworks-kr-1.dl.sourceforge.net/project/awstats/AWStats/7.0/awstats-7.0.zip<br />
</a>#unzip awstats-7.0.zip awstats<br />
#chmod +x /usr/local/awstats/tools/awstats_configure.pl<br />
#chmod +x /usr/local/awstats/wwwroot/cgi-bin/awstats.pl<br />
#chmod +x /usr/local/awstats/tools/awstats_buildstaticpages.pl<br />
#用来存放swstats的数据文件<br />
#mkdir /var/lib/awstats</p></blockquote>
<p><strong>二．创建配置文件</strong></p>
<blockquote><p>#cd /usr/local/awstats/tools/<br />
#perl ./awstats_configure.pl</p></blockquote>
<p>根据提示信息进行相应的操作即可．好像第一步让输入web的配置文件，由于这里用的是nginx．不是apache的．所以输入none跳过即可．</p>
<p>在后面提示的域名里我们输入我们要分析的域名，如<a href="http://www.haohtml.com" target="_blank">www.haohtml.com</a><span id="more-11129"></span></p>
<p>这里会自动创建/etc/awstats/awstats.www.haohtml.com.conf配置文件．里面有些日志文件的路径我们需要修改为实际日志的路径即可．还有日志的默认格式的，要写成</p>
<blockquote><p><span style="color: #0000ff;">LogFormat="%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot"</span></p></blockquote>
<p>这种格式才可以的．</p>
<p>我这里web的日志位置在<span style="color: #ff0000;">/var/log/httpd/haohtml/access.log</span></p>
<p><strong>三．配置Nginx</strong></p>
<p>为了方便，我们直接以独立域名的形式访问，如<a href="http://www.haohtml.com" target="_blank">http://awstats.haohtml.com</a></p>
<p>配置如下：</p>
<blockquote><p>server {<br />
server_name  awstats.haohtml.com;<br />
charset gb2312;</p>
<p>......<br />
root   /data/wwwroot/awstats;</p>
<p>access_log /var/log/httpd/haohtml/access.log;</p>
<p>#这里将日志关闭<br />
access_log off;</p>
<p>}</p></blockquote>
<p>重启Nginx，便虚拟主机配置生效．如果对虚拟主机配置不懂的话，可以参考：<a href="http://blog.haohtml.com/archives/6203">http://blog.haohtml.com/archives/6203</a></p>
<p><strong>四．定时分割日志文件</strong></p>
<blockquote><p>#vi <strong>/root/cut_nginx_log.sh<br />
</strong>#!/bin/bash<br />
mv /var/log/httpd/haothml/access.log /var/log/httpd/haothml/access_$(date -d "today" +"%Y%m%d").log<br />
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`</p></blockquote>
<p>添加脚本执行权限</p>
<blockquote><p>#chmod +x /root/cut_nginx_log.sh</p></blockquote>
<p>注意，执行完此命令后，会自动将access.log日志文件改名为当天日期为文件名的文件．一般在晚上24时前一两分钟执行此命令，放在crontab定时执行．</p>
<p><strong>五.创建awstats日志报告html目录</strong></p>
<blockquote><p>mkdir -p /data/wwwroot/awstats/<br />
cp -R /usr/local/awstats/wwwroot/css /data/wwwroot/awstats/<br />
cp -R /usr/local/awstats/wwwroot/icon /data/wwwroot/awstats/</p></blockquote>
<p><strong> 六．手动生成awstats日志分析数据库信息</strong></p>
<blockquote><p>/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.haohtml.com</p></blockquote>
<p>执行完以后，会把从日志里分析出来的结果存放在awstats的数据库里(结果存放位置为/var/lib/awstats),现在还没有办法查看，需要生成html日志报告才可以查看.</p>
<p><strong>七．生成html报告</strong></p>
<p>上面我们已经分析过了日志信息，这里我们将分析结果转换成html的格式，以便以网页的形式进行访问</p>
<blockquote><p>/usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.haohtml.com -dir=/data/wwwroot/awstats -lang=cn -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl</p></blockquote>
<p>这时，可以在浏览器里通过域名http://awstats.haohtml.com/awstats.www.haohtml.com.html访问了．</p>
<p><strong>八．放在crontab计划任务中</strong></p>
<p>在上面我们只是手动生成了html报告文件，这里让它自动完成这些操作.</p>
<p>编辑/etc/crontab文件，在最后添加以下两行</p>
<blockquote><p>#vi /etc/crontab<br />
59 23 * * *  /root/cut_nginx_log.sh<br />
58 23 * * * /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.haohtml.com -dir=/data/wwwroot/awstats -lang=cn -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl &gt;/dev/null 2&gt;&amp;1</p></blockquote>
<p><span style="color: #0000ff;"> 注意上面生成报道shell和切割nginx日志的时间先后顺序,先生成报道再切换日志的.</span></p>
<p>也可以让每10分钟生成一下静态报道页面.到23时58分时重新生成报道信息,在23时59分的时候进行切割日志.</p>
<p>*/10 * * * * /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.haohtml.com -dir=/data/wwwroot/awstats -lang=cn -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl &gt;/dev/null 2&gt;&amp;1</p>
<p>对于crontab的更多介绍可以参考:<a href="http://blog.haohtml.com/archives/4988">http://blog.haohtml.com/archives/4988</a></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="使用 awstats 分析 Nginx 的访问日志" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F7068&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11129">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用 awstats 分析 Nginx 的访问日志</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="安装awstats来分析apache的访问日志" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F675&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11129">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4023171.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">安装awstats来分析apache的访问日志</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12842&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11129">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用Nginx的proxy_cache缓存功能取代Squid[原创]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F3165&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11129">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4027570.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用Nginx的proxy_cache缓存功能取代Squid[原创]</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://blog.haohtml.com/archives/11129/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[教程]Nginx无缝升级教程</title>
		<link>http://blog.haohtml.com/archives/11025</link>
		<comments>http://blog.haohtml.com/archives/11025#comments</comments>
		<pubDate>Tue, 23 Aug 2011 11:52:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[服务器类]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://blog.haohtml.com/?p=11025</guid>
		<description><![CDATA[今天Nginx1.1.1发布了，准备将自己的nginx版本升级一下． 以下是我平滑将Nginx1.0.4升级到Nginx1.1.1的完整过程，作为一个教程或者备忘。 # /usr/local/nginx/sbin/nginx –V  //查看当前Nginx版本 nginx: nginx version: nginx/1.0.4 nginx: built by gcc 4.4.4 20100726 (Red Hat 4.4.4-13) (GCC) nginx: TLS SNI support enabled nginx: configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module 一.配置nginx并编译，切记不要make install # wget http://nginx.org/download/nginx-1.1.1.tar.gz # tar zxvf nginx-1.1.1.tar.gz # cd nginx-1.1.1 #./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module # make //开始编译 二.备份原来的nginx文件,使用最新的文件 [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="nginx源代码分析" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F6283&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11025">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4026128.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx源代码分析</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Nginx虚拟主机防Webshell完美版(图)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F2306&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11025">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022380.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Nginx虚拟主机防Webshell完美版(图)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx图片服务器的架构方案[2009-03-18 01:15:06]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1363&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11025">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022398.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx图片服务器的架构方案[2009-03-18 01:15:06]</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx 的限制连接模块limit_zone与limit_req_zone" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12640&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11025">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/03/25/18120978.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx 的限制连接模块limit_zone与limit_req_zone</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>今天Nginx1.1.1发布了，准备将自己的nginx版本升级一下．</p>
<p>以下是我平滑将Nginx1.0.4升级到Nginx1.1.1的完整过程，作为一个教程或者备忘。</p>
<blockquote><p># /usr/local/nginx/sbin/nginx –V  //查看当前Nginx版本</p>
<pre>nginx: nginx version: nginx/1.0.4
nginx: built by gcc 4.4.4 20100726 (Red Hat 4.4.4-13) (GCC)
nginx: TLS SNI support enabled
nginx: configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module</pre>
</blockquote>
<p>一.配置nginx并编译，切记不要make install</p>
<blockquote><p># wget http://nginx.org/download/nginx-1.1.1.tar.gz<br />
# tar zxvf nginx-1.1.1.tar.gz<br />
# cd nginx-1.1.1<br />
#./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module<br />
# make //开始编译</p></blockquote>
<p>二.备份原来的nginx文件,使用最新的文件</p>
<blockquote><p># mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old<br />
# cp objs/nginx /usr/local/nginx/sbin/</p></blockquote>
<p><span id="more-11025"></span>三.升级nginx</p>
<blockquote><p># make upgrade  //无缝升级，当前连接不会断开</p></blockquote>
<p>四.验证升级后Nginx的版本和配置</p>
<blockquote><p># /usr/local/nginx/sbin/nginx -V</p>
<pre>nginx: nginx version: nginx/1.1.1
nginx: built by gcc 4.4.4 20100726 (Red Hat 4.4.4-13) (GCC)
nginx: TLS SNI support enabled
nginx: configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module</pre>
</blockquote>
<p>可以看到nginx已经为最新的版本了!</p>
<p>整个升级过程完成！</p>
<p>转载请注明来源地址：<a href="http://blog.haohtml.com/archives/11025">http://blog.haohtml.com/archives/11025</a></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="nginx源代码分析" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F6283&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11025">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4026128.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx源代码分析</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Nginx虚拟主机防Webshell完美版(图)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F2306&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11025">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022380.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Nginx虚拟主机防Webshell完美版(图)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx图片服务器的架构方案[2009-03-18 01:15:06]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1363&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11025">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022398.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx图片服务器的架构方案[2009-03-18 01:15:06]</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx 的限制连接模块limit_zone与limit_req_zone" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12640&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F11025">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/03/25/18120978.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx 的限制连接模块limit_zone与limit_req_zone</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://blog.haohtml.com/archives/11025/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Nginx fastcgi perl (pl、cgi)支持</title>
		<link>http://blog.haohtml.com/archives/10909</link>
		<comments>http://blog.haohtml.com/archives/10909#comments</comments>
		<pubDate>Fri, 05 Aug 2011 15:57:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[服务器类]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://blog.haohtml.com/?p=10909</guid>
		<description><![CDATA[1. 安装FCGI模块 # wget http://search.cpan.org/CPAN/authors/id/B/BO/BOBTFISH/FCGI-0.70.tar.gz # tar zxvf FCGI-0.70.tar.gz # cd FCGI-0.70 # perl Makefile.PL # make # make install 2. 安装 IO 和 IO::ALL模块 # wget http://search.cpan.org/CPAN/authors/id/G/GB/GBARR/IO-1.25.tar.gz # tar zxvf IO-1.25.tar.gz # cd IO-1.25 # perl Makefile.PL # make # make install 升级MakeMaker版 #wget http://search.cpan.org/CPAN/authors/id/M/MS/MSCHWERN/ExtUtils-MakeMaker-6.54.tar.gz #tar zxvf  ExtUtils-MakeMaker-6.54 # perl Makefile.PL Checking if your [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="FreeBSD下nginx并支持php(fastcgi方式)配置详解" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1116&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F10909">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022445.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">FreeBSD下nginx并支持php(fastcgi方式)配置详解</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="[教程]FreeBSD下nginx+fast-cgi+mysql+zend的实现（php-fpm和spawn-fcgi）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1133&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F10909">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/07/21/18323627.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">[教程]FreeBSD下nginx+fast-cgi+mysql+zend的实现（php-fpm和spawn-fcgi）</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Nginx+PHP(FastCGI)搭建胜过Apache 10倍的Web服务器" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1125&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F10909">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022442.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Nginx+PHP(FastCGI)搭建胜过Apache 10倍的Web服务器</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12842&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F10909">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p><strong>1. 安装FCGI模块</strong></p>
<blockquote><p># wget http://search.cpan.org/CPAN/authors/id/B/BO/BOBTFISH/FCGI-0.70.tar.gz<br />
# tar zxvf FCGI-0.70.tar.gz<br />
# cd FCGI-0.70<br />
# perl Makefile.PL<br />
# make<br />
# make install</p></blockquote>
<div><strong>2. 安装 IO 和 IO::ALL模块</strong></div>
<blockquote><p># wget http://search.cpan.org/CPAN/authors/id/G/GB/GBARR/IO-1.25.tar.gz<br />
# tar zxvf IO-1.25.tar.gz<br />
# cd IO-1.25<br />
# perl Makefile.PL<br />
# make<br />
# make install</p>
<div><strong>升级MakeMaker版</strong></div>
<div>#wget http://search.cpan.org/CPAN/authors/id/M/MS/MSCHWERN/ExtUtils-MakeMaker-6.54.tar.gz<br />
#tar zxvf  ExtUtils-MakeMaker-6.54</div>
<div># perl Makefile.PL</div>
<div>Checking if your kit is complete...</div>
<div>Looks good</div>
<div>Using included version of ExtUtils::Manifest (1.56) as it is newer than the installed version (1.46).</div>
<div>Using included version of ExtUtils::Command (1.16) as it is newer than the installed version (1.09).</div>
<div>Using included version of ExtUtils::Installed (1.43) as it is newer than the installed version (0.08).</div>
<div>Using included version of ExtUtils::Packlist (1.43) as it is newer than the installed version (0.04).</div>
<div>Using included version of ExtUtils::Install (1.52) as it is newer than the installed version (1.33).</div>
<div>Writing Makefile for ExtUtils::MakeMaker</div>
<div>make</div>
<div>make install</div>
<p># wget http://search.cpan.org/CPAN/authors/id/I/IN/INGY/IO-All-0.41.tar.gz<br />
# tar zxvf IO-All-0.41.tar.gz<br />
# cd IO-All<br />
# perl Makefile.PL<br />
# make<br />
# make install</p></blockquote>
<p><strong>3. Perl脚本<span id="more-10909"></span></strong></p>
<p><a href="http://blog.haohtml.com/wp-content/uploads/2011/08/perl-fcgi.zip">点击下载Perl脚本perl-fcgi</a></p>
<p>我把这个脚本放在 /usr/local/nginx/perl-fcgi.pl</p>
<blockquote><p># chmod 755 /usr/local/nginx/perl-fcgi.pl</p></blockquote>
<p><strong>4.cgi启动/停止脚本</strong> (nobody为nginx的运行用户)</p>
<p># vi /usr/local/nginx/start_perl_cgi.sh</p>
<pre class="brush: bash; title: ; notranslate" title="">#!/bin/bash
#set -x
dir=/usr/local/nginx

stop ()
{
#pkill  -f  $dir/perl-fcgi.pl
kill $(cat $dir/logs/perl-fcgi.pid)
rm $dir/logs/perl-fcgi.pid 2&gt;/dev/null
rm $dir/logs/perl-fcgi.sock 2&gt;/dev/null
echo "stop perl-fcgi done"
}

start ()
{
rm $dir/now_start_perl_fcgi.sh 2&gt;/dev/null

chown nobody.root $dir/logs
echo "$dir/perl-fcgi.pl -l $dir/logs/perl-fcgi.log -pid $dir/logs/perl-fcgi.pid -S $dir/logs/perl-fcgi.sock" &gt;&gt;$dir/now_start_perl_fcgi.sh

chown nobody.nobody $dir/now_start_perl_fcgi.sh
chmod u+x $dir/now_start_perl_fcgi.sh

sudo -u nobody $dir/now_start_perl_fcgi.sh
echo "start perl-fcgi done"
}

case $1 in
stop)
stop
;;
start)
start
;;
restart)
stop
start
;;
esac</pre>
<blockquote><p># chmod 755 /usr/local/nginx/start_perl_cgi.sh</p></blockquote>
<p># 启动脚本</p>
<blockquote><p># /usr/local/nginx/start_perl_cgi.sh start</p></blockquote>
<p>正常情况下在/usr/local/nginx/logs 下生成 perl-fcgi.sock 这个文件,如果没有生成,那就要检查下上面的步聚了.</p>
<p><strong>5. 配置nginx</strong></p>
<pre class="brush: plain; title: ; notranslate" title="">server {
    listen       80;
    server_name  _;
    location / {
        root   /usr/local/nginx/html;
        index  index.html index.htm index.cgi;
    }
    location ~ .*\.(pl|cgi)?$
    {
      gzip off;
      root   /data/nginx/html;
      fastcgi_pass  unix:/usr/local/nginx/logs/perl-fcgi.sock;
      fastcgi_index index.cgi;
      fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
      fastcgi_param  SERVER_SOFTWARE    nginx;
      fastcgi_param  QUERY_STRING       $query_string;
      fastcgi_param  REQUEST_METHOD     $request_method;
      fastcgi_param  CONTENT_TYPE       $content_type;
      fastcgi_param  CONTENT_LENGTH     $content_length;
      fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
      fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
      fastcgi_param  REQUEST_URI        $request_uri;
      fastcgi_param  DOCUMENT_URI       $document_uri;
      fastcgi_param  DOCUMENT_ROOT      $document_root;
      fastcgi_param  SERVER_PROTOCOL    $server_protocol;
      fastcgi_param  REMOTE_ADDR        $remote_addr;
      fastcgi_param  REMOTE_PORT        $remote_port;
      fastcgi_param  SERVER_ADDR        $server_addr;
      fastcgi_param  SERVER_PORT        $server_port;
      fastcgi_param  SERVER_NAME        $server_name;
      fastcgi_read_timeout   60;
     }
}</pre>
<p><strong>6.Perl探针测试</strong></p>
<p><a href="http://www.xtgly.com/wp-content/uploads/2010/09/perlinfo.zip">点击下载Perl探针</a></p>
<p>转载:<a href="http://www.xtgly.com/2010/09/20/nginx-fastcgi-perl-pl%E3%80%81cgi%E6%94%AF%E6%8C%81.htm">http://www.xtgly.com/2010/09/20/nginx-fastcgi-perl-pl%E3%80%81cgi%E6%94%AF%E6%8C%81.htm</a></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="FreeBSD下nginx并支持php(fastcgi方式)配置详解" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1116&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F10909">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022445.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">FreeBSD下nginx并支持php(fastcgi方式)配置详解</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="[教程]FreeBSD下nginx+fast-cgi+mysql+zend的实现（php-fpm和spawn-fcgi）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1133&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F10909">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/07/21/18323627.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">[教程]FreeBSD下nginx+fast-cgi+mysql+zend的实现（php-fpm和spawn-fcgi）</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Nginx+PHP(FastCGI)搭建胜过Apache 10倍的Web服务器" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F1125&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F10909">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/22/4022442.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Nginx+PHP(FastCGI)搭建胜过Apache 10倍的Web服务器</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F12842&from=http%3A%2F%2Fblog.haohtml.com%2Farchives%2F10909">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">nginx: [warn] the &quot;log_format&quot; directive may be used only on &quot;http&quot; level ．．．解决办法</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://blog.haohtml.com/archives/10909/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

