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

<channel>
	<title>柠檬工作室 &#187; Nginx</title>
	<atom:link href="http://www.crazylemon.net/category/nginx/feed" rel="self" type="application/rss+xml" />
	<link>http://www.crazylemon.net</link>
	<description>上帝无用，天使无用</description>
	<lastBuildDate>Thu, 17 Nov 2011 19:39:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>nginx文件类型错误解析漏洞(80sec)</title>
		<link>http://www.crazylemon.net/nginx/3168.html</link>
		<comments>http://www.crazylemon.net/nginx/3168.html#comments</comments>
		<pubDate>Fri, 21 May 2010 13:18:17 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Html]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[robot]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[timeout]]></category>
		<category><![CDATA[配置]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=3168</guid>
		<description><![CDATA[漏洞介绍：nginx是一款高性能的web服务器，使用非常广泛，其不仅经常被用作反向代理，也可以非常好的支持PHP的运行。80sec发现其中存在一个较为严重的安全问题，默认情况下可能导致服务器错误的将任何类型的文件以PHP的方式进行解析，这将导致严重的安全问题，使得恶意的攻击者可能攻陷支持php的nginx服务器。 漏洞分析：nginx默认以cgi的方式支持php的运行，譬如在配置文件当中可以以 location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; } 的方式支持对php的解析，location对请求进行选择的时候会使用URI环境变量进行选择，其中传递到后端Fastcgi的关键变量SCRIPT_FILENAME由nginx生成的$fastcgi_script_name决定，而通过分析可以看到$fastcgi_script_name是直接由URI环境变量控制的，这里就是产生问题的点。而为了较好的支持PATH_INFO的提取，在PHP的配置选项里存在cgi.fix_pathinfo选项，其目的是为了从SCRIPT_FILENAME里取出真正的脚本名。 那么假设存在一个http://www.80sec.com/80sec.jpg，我们以如下的方式去访问 将会得到一个URI /80sec.jpg/80sec.php 经过location指令，该请求将会交给后端的fastcgi处理，nginx为其设置环境变量SCRIPT_FILENAME，内容为 /scripts/80sec.jpg/80sec.php 而在其他的webserver如lighttpd当中，我们发现其中的SCRIPT_FILENAME被正确的设置为 /scripts/80sec.jpg 所以不存在此问题。 后端的fastcgi在接受到该选项时，会根据fix_pathinfo配置决定是否对SCRIPT_FILENAME进行额外的处理，一般情况下如果不对fix_pathinfo进行设置将影响使用PATH_INFO进行路由选择的应用，所以该选项一般配置开启。Php通过该选项之后将查找其中真正的脚本文件名字，查找的方式也是查看文件是否存在，这个时候将分离出SCRIPT_FILENAME和PATH_INFO分别为 /scripts/80sec.jpg和80sec.php 最后，以/scripts/80sec.jpg作为此次请求需要执行的脚本，攻击者就可以实现让nginx以php来解析任何类型的文件了。 http://www.80sec.com/80sec.jpg/80sec.php   POC： 访问一个nginx来支持php的站点，在一个任何资源的文件如robots.txt后面加上/80sec.php，这个时候你可以看到如下的区别： 访问http://www.80sec.com/robots.txt HTTP/1.1 200 OK Server: nginx/0.6.32 Date: Thu, 20 May 2010 10:05:30 GMT Content-Type: text/plain Content-Length: 18 Last-Modified: Thu, 20 May [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>漏洞介绍：nginx是一款高性能的web服务器，使用非常广泛，其不仅经常被用作反向代理，也可以非常好的支持PHP的运行。80sec发现其中存在一个较为严重的安全问题，默认情况下可能导致服务器错误的将任何类型的文件以PHP的方式进行解析，这将导致严重的安全问题，使得恶意的攻击者可能攻陷支持php的nginx服务器。<br />
漏洞分析：nginx默认以cgi的方式支持php的运行，譬如在配置文件当中可以以</p>
<p><code><br />
location ~ \.php$ {<br />
root html;<br />
fastcgi_pass 127.0.0.1:9000;<br />
fastcgi_index index.php;<br />
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;<br />
include fastcgi_params;<br />
}<br />
</code><br />
的方式支持对php的解析，location对请求进行选择的时候会使用URI环境变量进行选择，其中传递到后端Fastcgi的关键变量SCRIPT_FILENAME由nginx生成的$fastcgi_script_name决定，而通过分析可以看到$fastcgi_script_name是直接由URI环境变量控制的，这里就是产生问题的点。而为了较好的支持PATH_INFO的提取，在PHP的配置选项里存在cgi.fix_pathinfo选项，其目的是为了从SCRIPT_FILENAME里取出真正的脚本名。<br />
那么假设存在一个http://www.80sec.com/80sec.jpg，我们以如下的方式去访问</p>
<p>将会得到一个URI<br />
<code><br />
/80sec.jpg/80sec.php<br />
</code><br />
经过location指令，该请求将会交给后端的fastcgi处理，nginx为其设置环境变量SCRIPT_FILENAME，内容为<br />
<code><br />
/scripts/80sec.jpg/80sec.php<br />
</code><br />
而在其他的webserver如lighttpd当中，我们发现其中的SCRIPT_FILENAME被正确的设置为<br />
<code><br />
/scripts/80sec.jpg<br />
</code><br />
所以不存在此问题。<br />
后端的fastcgi在接受到该选项时，会根据fix_pathinfo配置决定是否对SCRIPT_FILENAME进行额外的处理，一般情况下如果不对fix_pathinfo进行设置将影响使用PATH_INFO进行路由选择的应用，所以该选项一般配置开启。Php通过该选项之后将查找其中真正的脚本文件名字，查找的方式也是查看文件是否存在，这个时候将分离出SCRIPT_FILENAME和PATH_INFO分别为<br />
<code><br />
/scripts/80sec.jpg和80sec.php<br />
</code><br />
最后，以/scripts/80sec.jpg作为此次请求需要执行的脚本，攻击者就可以实现让nginx以php来解析任何类型的文件了。</p>
<p>http://www.80sec.com/80sec.jpg/80sec.php</p>
<p> </p>
<p>POC： 访问一个nginx来支持php的站点，在一个任何资源的文件如robots.txt后面加上/80sec.php，这个时候你可以看到如下的区别：</p>
<p>访问http://www.80sec.com/robots.txt<br />
<code><br />
HTTP/1.1 200 OK<br />
Server: nginx/0.6.32<br />
Date: Thu, 20 May 2010 10:05:30 GMT<br />
Content-Type: text/plain<br />
Content-Length: 18<br />
Last-Modified: Thu, 20 May 2010 06:26:34 GMT<br />
Connection: keep-alive<br />
Keep-Alive: timeout=20<br />
Accept-Ranges: bytes<br />
</code><br />
访问访问http://www.80sec.com/robots.txt/80sec.php<br />
<code><br />
HTTP/1.1 200 OK<br />
Server: nginx/0.6.32<br />
Date: Thu, 20 May 2010 10:06:49 GMT<br />
Content-Type: text/html<br />
Transfer-Encoding: chunked<br />
Connection: keep-alive<br />
Keep-Alive: timeout=20<br />
X-Powered-By: PHP/5.2.6<br />
</code><br />
其中的Content-Type的变化说明了后端负责解析的变化，该站点就可能存在漏洞。</p>
<p>漏洞厂商：http://www.nginx.org</p>
<p>解决方案：</p>
<p>我们已经尝试联系官方，但是此前你可以通过以下的方式来减少损失<br />
<code><br />
关闭cgi.fix_pathinfo为0<br />
</code><br />
或者<br />
<code><br />
if ( $fastcgi_script_name ~ \..*\/.*php ) {<br />
return 403;<br />
}</code></div>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>06/16/2009 -- <a href="http://www.crazylemon.net/nginx/670.html" title="nginx.conf &#8211; nginx配置文件说明">nginx.conf &#8211; nginx配置文件说明</a> (1)</li><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/510.html" title="nginx详解">nginx详解</a> (0)</li><li>02/07/2009 -- <a href="http://www.crazylemon.net/nginx/74.html" title="nginx配置详细说明">nginx配置详细说明</a> (0)</li><li>07/18/2009 -- <a href="http://www.crazylemon.net/web/1239.html" title=".htaccess使用指南">.htaccess使用指南</a> (0)</li><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/504.html" title="Nginx的WordPress配置">Nginx的WordPress配置</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/nginx/3168.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>深究Nginx502 bad gateway, 504 Gateway Time-out的彻底解决（转）</title>
		<link>http://www.crazylemon.net/nginx/1552.html</link>
		<comments>http://www.crazylemon.net/nginx/1552.html#comments</comments>
		<pubDate>Tue, 11 Aug 2009 01:14:14 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[DIV+CSS]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[Gateway]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php-fpm]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[timeout]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=1552</guid>
		<description><![CDATA[我的VPS是256M的内存，CPU是四核心的，所以更多的我会在乎内存。而在我调试服务器的时候通常会遇到Nginx502 bad gateway和504 Gateway Time-out的错误。分析nginx.conf我发现server和fastcgi的buffers过多，导致fastcgi请求的数量过大，php-fpm无法及时处理而出错。循此思路我们可以再总体buffers不变的情况下减少请求数量，具体的ningx.conf改动细节如下：                 server_names_hash_bucket_size 128;                 client_header_buffer_size 32k;                 large_client_header_buffers 1 128k;# 4 32k                 client_max_body_size 8m;                 sendfile on;                 tcp_nopush     on;                 keepalive_timeout 60;                 tcp_nodelay on;                 fastcgi_connect_timeout 300;                 fastcgi_send_timeout 300;                 fastcgi_read_timeout 300;                 fastcgi_buffer_size 128k;                 fastcgi_buffers 2 256k;#8 128                 fastcgi_busy_buffers_size 256k;                 fastcgi_temp_file_write_size 256k; [...]]]></description>
			<content:encoded><![CDATA[<p>我的VPS是256M的内存，CPU是四核心的，所以更多的我会在乎内存。而在我调试服务器的时候通常会遇到Nginx502 bad gateway和504 Gateway Time-out的错误。分析nginx.conf我发现server和fastcgi的buffers过多，导致fastcgi请求的数量过大，php-fpm无法及时处理而出错。循此思路我们可以再总体buffers不变的情况下减少请求数量，具体的ningx.conf改动细节如下：<br />
                server_names_hash_bucket_size 128;<br />
                client_header_buffer_size 32k;<br />
                large_client_header_buffers 1 128k;# 4 32k<br />
                client_max_body_size 8m;</p>
<p>                sendfile on;<br />
                tcp_nopush     on;</p>
<p>                keepalive_timeout 60;</p>
<p>                tcp_nodelay on;</p>
<p>                fastcgi_connect_timeout 300;<br />
                fastcgi_send_timeout 300;<br />
                fastcgi_read_timeout 300;<br />
                fastcgi_buffer_size 128k;<br />
                fastcgi_buffers 2 256k;#8 128<br />
                fastcgi_busy_buffers_size 256k;<br />
                fastcgi_temp_file_write_size 256k;<br />
                fastcgi_intercept_errors on;</p>
<p>                gzip on;<br />
                gzip_min_length  1k;<br />
                gzip_buffers     1 64k; #4 16<br />
                gzip_http_version 1.0;<br />
                gzip_comp_level 2;<br />
                gzip_types       text/plain application/x-javascript text/css application/xml;<br />
                gzip_vary on;</p>
<p>另外，php-fpm的默认静态处理方式会使得php-cgi的进程长期占用内存而无法释放，这也是导致nginx出错的原因之一，因此可以将php-fpm的处理方式改成apache模式。<br />
        &lt;value name=”style”&gt;apache-like&lt;/value&gt;</p>
<p>从更改完毕到现在的测试表明上述方式的效果还是很明显的，并没有发现一次Nginx502 bad gateway或504 Gateway Time-out错误。当然，如果你的VPS或者服务器的性能足够好可以根据具体情况不必做无谓的改动。</p>
<p> </p>
<p>以上摘自疯人醉语</p>
<p>测试一下，有效果的话会更新</p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>02/07/2009 -- <a href="http://www.crazylemon.net/nginx/74.html" title="nginx配置详细说明">nginx配置详细说明</a> (0)</li><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/510.html" title="nginx详解">nginx详解</a> (0)</li><li>05/28/2009 -- <a href="http://www.crazylemon.net/nginx/211.html" title="Nginx服务器安装Magento">Nginx服务器安装Magento</a> (1)</li><li>06/26/2009 -- <a href="http://www.crazylemon.net/work/834.html" title="13个测试网站访问速度的服务网站">13个测试网站访问速度的服务网站</a> (1)</li><li>06/16/2009 -- <a href="http://www.crazylemon.net/nginx/670.html" title="nginx.conf &#8211; nginx配置文件说明">nginx.conf &#8211; nginx配置文件说明</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/nginx/1552.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>今天发现的一个502 bad gateway可能</title>
		<link>http://www.crazylemon.net/php/1391.html</link>
		<comments>http://www.crazylemon.net/php/1391.html#comments</comments>
		<pubDate>Tue, 28 Jul 2009 20:03:29 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Gateway]]></category>
		<category><![CDATA[php-fpm]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=1391</guid>
		<description><![CDATA[在执行较长的PHP脚本时，如果正好来个 /usr/local/php/sbin/php-fpm reload 虽然说是平滑过渡，但也会造成502 bad gateway，无语了 以前以为只有/usr/local/php/sbin/php-fpm restart会造成这样 相关日志08/11/2009 -- 深究Nginx502 bad gateway, 504 Gateway Time-out的彻底解决（转） (0)06/08/2009 -- bind() for address &#8217;127.0.0.1:9000&#8242; failed: Address already in use (0)11/17/2009 -- GSPAY更新for zen cart (0)07/28/2009 -- linux 的计划任务 crond 服务 (0)07/23/2009 -- cannot restore segment prot after reloc: Permission denied (0)]]></description>
			<content:encoded><![CDATA[<p>在执行较长的PHP脚本时，如果正好来个</p>
<p>/usr/local/php/sbin/php-fpm reload</p>
<p>虽然说是平滑过渡，但也会造成502 bad gateway，无语了</p>
<p>以前以为只有/usr/local/php/sbin/php-fpm restart会造成这样</p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>08/11/2009 -- <a href="http://www.crazylemon.net/nginx/1552.html" title="深究Nginx502 bad gateway, 504 Gateway Time-out的彻底解决（转）">深究Nginx502 bad gateway, 504 Gateway Time-out的彻底解决（转）</a> (0)</li><li>06/08/2009 -- <a href="http://www.crazylemon.net/php/567.html" title="bind() for address &#8217;127.0.0.1:9000&#8242; failed: Address already in use">bind() for address &#8217;127.0.0.1:9000&#8242; failed: Address already in use</a> (0)</li><li>11/17/2009 -- <a href="http://www.crazylemon.net/zencart/2506.html" title="GSPAY更新for zen cart">GSPAY更新for zen cart</a> (0)</li><li>07/28/2009 -- <a href="http://www.crazylemon.net/linux/1389.html" title="linux 的计划任务 crond 服务">linux 的计划任务 crond 服务</a> (0)</li><li>07/23/2009 -- <a href="http://www.crazylemon.net/linux/1333.html" title="cannot restore segment prot after reloc: Permission denied ">cannot restore segment prot after reloc: Permission denied </a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/php/1391.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx rewrite 参数</title>
		<link>http://www.crazylemon.net/nginx/1096.html</link>
		<comments>http://www.crazylemon.net/nginx/1096.html#comments</comments>
		<pubDate>Fri, 10 Jul 2009 17:25:01 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[正则表达式]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=1096</guid>
		<description><![CDATA[正则表达式匹配，其中： * ~ 为区分大小写匹配 * ~* 为不区分大小写匹配 * !~和!~*分别为区分大小写不匹配及不区分大小写不匹配 文件及目录匹配，其中： * -f和!-f用来判断是否存在文件 * -d和!-d用来判断是否存在目录 * -e和!-e用来判断是否存在文件或目录 * -x和!-x用来判断文件是否可执行 flag标记有： * last 相当于Apache里的[L]标记，表示完成rewrite * break 终止匹配, 不再匹配后面的规则 * redirect 返回302临时重定向 * permanent 返回301永久重定向 一些可用的全局变量有，可以用做条件判断(待补全) $args $content_length $content_type $document_root $document_uri $host $http_user_agent $http_cookie $limit_rate $request_body_file $request_method $remote_addr $remote_port $remote_user $request_filename $request_uri $query_string $scheme $server_protocol $server_addr $server_name $server_port [...]]]></description>
			<content:encoded><![CDATA[<p>正则表达式匹配，其中：</p>
<p>* ~ 为区分大小写匹配<br />
* ~* 为不区分大小写匹配<br />
* !~和!~*分别为区分大小写不匹配及不区分大小写不匹配</p>
<p>文件及目录匹配，其中：</p>
<p>* -f和!-f用来判断是否存在文件<br />
* -d和!-d用来判断是否存在目录<br />
* -e和!-e用来判断是否存在文件或目录<br />
* -x和!-x用来判断文件是否可执行</p>
<p>flag标记有：</p>
<p>* last 相当于Apache里的[L]标记，表示完成rewrite<br />
* break 终止匹配, 不再匹配后面的规则<br />
* redirect 返回302临时重定向<br />
* permanent 返回301永久重定向</p>
<p>一些可用的全局变量有，可以用做条件判断(待补全)</p>
<p>$args<br />
$content_length<br />
$content_type<br />
$document_root<br />
$document_uri<br />
$host<br />
$http_user_agent<br />
$http_cookie<br />
$limit_rate<br />
$request_body_file<br />
$request_method<br />
$remote_addr<br />
$remote_port<br />
$remote_user<br />
$request_filename<br />
$request_uri<br />
$query_string<br />
$scheme<br />
$server_protocol<br />
$server_addr<br />
$server_name<br />
$server_port<br />
$uri</p>
<p>结合QeePHP的例子</p>
<p>if (!-d $request_filename) {<br />
rewrite ^/([a-z-A-Z]+)/([a-z-A-Z]+)/?(.*)$ /index.php?namespace=user&amp;controller=$1&amp;action=$2&amp;$3 last;<br />
rewrite ^/([a-z-A-Z]+)/?$ /index.php?namespace=user&amp;controller=$1 last;<br />
break;<br />
}</p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/510.html" title="nginx详解">nginx详解</a> (0)</li><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/504.html" title="Nginx的WordPress配置">Nginx的WordPress配置</a> (0)</li><li>05/28/2009 -- <a href="http://www.crazylemon.net/nginx/211.html" title="Nginx服务器安装Magento">Nginx服务器安装Magento</a> (1)</li><li>05/21/2010 -- <a href="http://www.crazylemon.net/nginx/3168.html" title="nginx文件类型错误解析漏洞(80sec)">nginx文件类型错误解析漏洞(80sec)</a> (0)</li><li>09/10/2009 -- <a href="http://www.crazylemon.net/apache/1796.html" title="Apache服务器wordpress设置永久连接后怎么去掉INDEX.PHP">Apache服务器wordpress设置永久连接后怎么去掉INDEX.PHP</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/nginx/1096.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wordpress多用户版服务器配置</title>
		<link>http://www.crazylemon.net/nginx/941.html</link>
		<comments>http://www.crazylemon.net/nginx/941.html#comments</comments>
		<pubDate>Thu, 02 Jul 2009 02:10:17 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[word]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[配置]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=941</guid>
		<description><![CDATA[nginx上，只要server_name 设置为 *.crazylemon.net 通配所有子域名 域名解析时，也只要设 *  A记录到服务器IP即可 不要一个个来，方便多了，为自己早上错误的想法寒一个。。。 相关日志02/06/2010 -- LiteSpeed web服务器 (0)06/06/2009 -- Nginx的WordPress配置 (0)06/29/2010 -- wordpress3.0发布，支持多站点 (1)05/21/2010 -- nginx文件类型错误解析漏洞(80sec) (0)09/10/2009 -- Apache服务器wordpress设置永久连接后怎么去掉INDEX.PHP (1)]]></description>
			<content:encoded><![CDATA[<p>nginx上，只要server_name 设置为 *.crazylemon.net 通配所有子域名</p>
<p>域名解析时，也只要设 *  A记录到服务器IP即可</p>
<p>不要一个个来，方便多了，为自己早上错误的想法寒一个。。。</p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>02/06/2010 -- <a href="http://www.crazylemon.net/web/2887.html" title="LiteSpeed web服务器">LiteSpeed web服务器</a> (0)</li><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/504.html" title="Nginx的WordPress配置">Nginx的WordPress配置</a> (0)</li><li>06/29/2010 -- <a href="http://www.crazylemon.net/wordpress/3239.html" title="wordpress3.0发布，支持多站点">wordpress3.0发布，支持多站点</a> (1)</li><li>05/21/2010 -- <a href="http://www.crazylemon.net/nginx/3168.html" title="nginx文件类型错误解析漏洞(80sec)">nginx文件类型错误解析漏洞(80sec)</a> (0)</li><li>09/10/2009 -- <a href="http://www.crazylemon.net/apache/1796.html" title="Apache服务器wordpress设置永久连接后怎么去掉INDEX.PHP">Apache服务器wordpress设置永久连接后怎么去掉INDEX.PHP</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/nginx/941.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>测试nginx配置文件的方法</title>
		<link>http://www.crazylemon.net/nginx/673.html</link>
		<comments>http://www.crazylemon.net/nginx/673.html#comments</comments>
		<pubDate>Tue, 16 Jun 2009 14:19:50 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[配置]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=673</guid>
		<description><![CDATA[/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf -t 表示test -c 指定目标文件 成功则显示 the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok configuration file /usr/local/nginx/conf/nginx.conf test is successful   nginx的几个命令参数 Nginx 安装后只有一个程序文件，本身并不提供各种管理程序，它是使用参数和系统信号机制对 Nginx 进程本身进行控制的。 Nginx 的参数包括有如下几个：     -c &#60;path_to_config&#62;：使用指定的配置文件而不是 conf 目录下的 nginx.conf 。     -t：测试配置文件是否正确，在运行时需要重新加载配置的时候，此命令非常重要，用来检测所修改的配置文件是否有语法错误。     -v：显示 nginx 版本号。     -V：显示 nginx 的版本号以及编译环境信息以及编译时的参数。 相关日志06/06/2009 -- nginx详解 (0)06/03/2009 -- Nginx的UrlRewrite配置 (0)05/28/2009 -- [...]]]></description>
			<content:encoded><![CDATA[<p><span style="FONT-WEIGHT: bold; COLOR: #000000">/</span>usr<span style="FONT-WEIGHT: bold; COLOR: #000000">/</span>local<span style="FONT-WEIGHT: bold; COLOR: #000000">/</span>nginx<span style="FONT-WEIGHT: bold; COLOR: #000000">/</span>sbin<span style="FONT-WEIGHT: bold; COLOR: #000000">/</span>nginx <span style="COLOR: #660033">-t</span> <span style="COLOR: #660033">-c</span> <span style="FONT-WEIGHT: bold; COLOR: #000000">/</span>usr<span style="FONT-WEIGHT: bold; COLOR: #000000">/</span>local<span style="FONT-WEIGHT: bold; COLOR: #000000">/</span>nginx<span style="FONT-WEIGHT: bold; COLOR: #000000">/</span>conf<span style="FONT-WEIGHT: bold; COLOR: #000000">/</span>nginx.conf</p>
<p>-t 表示test</p>
<p>-c 指定目标文件</p>
<p>成功则显示</p>
<p>the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok<br />
configuration file /usr/local/nginx/conf/nginx.conf test is successful</p>
<p> </p>
<p>nginx的几个命令参数</p>
<p>Nginx 安装后只有一个程序文件，本身并不提供各种管理程序，它是使用参数和系统信号机制对 Nginx 进程本身进行控制的。 Nginx 的参数包括有如下几个：</p>
<p>    -c &lt;path_to_config&gt;：使用指定的配置文件而不是 conf 目录下的 nginx.conf 。</p>
<p>    -t：<a href="http://softtest.chinaitlab.com/" target="_blank">测试</a>配置文件是否正确，在运行时需要重新加载配置的时候，此命令非常重要，用来检测所修改的配置文件是否有语法错误。</p>
<p>    -v：显示 nginx 版本号。</p>
<p>    -V：显示 nginx 的版本号以及编译环境信息以及编译时的参数。</p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/510.html" title="nginx详解">nginx详解</a> (0)</li><li>06/03/2009 -- <a href="http://www.crazylemon.net/php/416.html" title="Nginx的UrlRewrite配置">Nginx的UrlRewrite配置</a> (0)</li><li>05/28/2009 -- <a href="http://www.crazylemon.net/nginx/211.html" title="Nginx服务器安装Magento">Nginx服务器安装Magento</a> (1)</li><li>02/07/2009 -- <a href="http://www.crazylemon.net/nginx/74.html" title="nginx配置详细说明">nginx配置详细说明</a> (0)</li><li>09/01/2010 -- <a href="http://www.crazylemon.net/mysql/3455.html" title="mysql 注入方法（转自Security Angel）">mysql 注入方法（转自Security Angel）</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/nginx/673.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx.conf &#8211; nginx配置文件说明</title>
		<link>http://www.crazylemon.net/nginx/670.html</link>
		<comments>http://www.crazylemon.net/nginx/670.html#comments</comments>
		<pubDate>Tue, 16 Jun 2009 14:16:21 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Charset]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[Html]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[timeout]]></category>
		<category><![CDATA[虚拟主机]]></category>
		<category><![CDATA[配置]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=670</guid>
		<description><![CDATA[#用户和用户组 user www www; #指令指定处理进程的数量。一般推荐为处理器的个数. 可以适当增加，以避免进程在堵塞在IO等待中。 worker_processes 8; #错误日志 error_log logs/error.log; #pid文件位置 pid logs/nginx.pid; events { #指定 nginx 处理进程的个数，其与总处理量的关系用公式表达如下： #MaxClient = worker_processes * worker_connections #因此这两个数的乘积若大于系统最大可用tcp/ip栈数是没有意义的. worker_connections 1024; } #HTTP 请求设置 http { #载入mime类型 include mime.types; #默认类型 default_type application/octet-stream; #日志的格式 log_format main ‘$remote_addr &#8211; $remote_user [$time_local] “$request” ‘ ‘$status $body_bytes_sent “$http_referer” ‘ ‘”$http_user_agent” “$http_x_forwarded_for”‘; #访问日志 access_log [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>#用户和用户组<br />
user www www;</p>
<p>#指令指定处理进程的数量。一般推荐为处理器的个数. 可以适当增加，以避免进程在堵塞在IO等待中。<br />
worker_processes 8;</p>
<p>#错误日志<br />
error_log logs/error.log;</p>
<p>#pid文件位置<br />
pid logs/nginx.pid;</p>
<p>events {<br />
#指定 nginx 处理进程的个数，其与总处理量的关系用公式表达如下：<br />
#MaxClient = worker_processes * worker_connections<br />
#因此这两个数的乘积若大于系统最大可用tcp/ip栈数是没有意义的.<br />
worker_connections 1024;<br />
}</p>
<p>#HTTP 请求设置<br />
http {<br />
#载入mime类型<br />
include mime.types;<br />
#默认类型<br />
default_type application/octet-stream;</p>
<p>#日志的格式<br />
log_format main ‘$remote_addr &#8211; $remote_user [$time_local] “$request” ‘<br />
‘$status $body_bytes_sent “$http_referer” ‘<br />
‘”$http_user_agent” “$http_x_forwarded_for”‘;</p>
<p>#访问日志<br />
access_log logs/access.log main;</p>
<p>#sendfile 指令指定 nginx 是否调用 sendfile 函数（zero copy 方式）来输出文件，<br />
#对于普通应用，必须设为 on。<br />
#如果用来进行下载等应用磁盘IO重负载应用，可设置为 off，以平衡磁盘与网络IO处理速度，降低系统 uptime。<br />
sendfile on;</p>
<p>tcp_nopush on;</p>
<p>#keepalive_timeout 0;<br />
keepalive_timeout 65;</p>
<p>#gzip on;</p>
<p>#服务器设置<br />
server {<br />
#监听端口<br />
listen 80;</p>
<p>#WEB服务主机名<br />
server_name localhost;</p>
<p>#charset utf-8;</p>
<p>#访问日志<br />
access_log logs/localhost.access.log main;</p>
<p>#请求规则 默认请求<br />
location / {<br />
#WEB根目录<br />
root /home/www/www;<br />
#默认索引文件名<br />
index index.html index.htm index.php;<br />
}</p>
<p>#页面不存在处理<br />
error_page 404 /404.html;</p>
<p>#服务器错误定向<br />
error_page 500 502 503 504 /50x.html;<br />
location = /50x.html {<br />
root /home/www/www;<br />
}<br />
#PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.<br />
location ~ \.php$ {<br />
root /home/www/www;<br />
fastcgi_pass 127.0.0.1:9000;<br />
fastcgi_index index.php;<br />
fastcgi_param SCRIPT_FILENAME /home/www/www$fastcgi_script_name;<br />
include fastcgi_params;<br />
}</p>
<p>#禁止访问 .htxxx 文件<br />
location ~ /\.ht {<br />
deny all;<br />
}<br />
}<br />
}</p></blockquote>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/510.html" title="nginx详解">nginx详解</a> (0)</li><li>02/07/2009 -- <a href="http://www.crazylemon.net/nginx/74.html" title="nginx配置详细说明">nginx配置详细说明</a> (0)</li><li>05/21/2010 -- <a href="http://www.crazylemon.net/nginx/3168.html" title="nginx文件类型错误解析漏洞(80sec)">nginx文件类型错误解析漏洞(80sec)</a> (0)</li><li>07/18/2009 -- <a href="http://www.crazylemon.net/web/1239.html" title=".htaccess使用指南">.htaccess使用指南</a> (0)</li><li>04/10/2010 -- <a href="http://www.crazylemon.net/php/3068.html" title="GOOGLE翻墙代码">GOOGLE翻墙代码</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/nginx/670.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>osCommerce 在 nginx 上的 rewrite 规则</title>
		<link>http://www.crazylemon.net/nginx/620.html</link>
		<comments>http://www.crazylemon.net/nginx/620.html#comments</comments>
		<pubDate>Fri, 12 Jun 2009 15:39:53 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Html]]></category>
		<category><![CDATA[Link]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[rewrite]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=620</guid>
		<description><![CDATA[location / {  if (!-e $request_filename)  { rewrite “^(.*)-p-(.*).html” /product_info.php?products_id=$2%1; rewrite “^(.*)-p-(.*).html” /product_info.php?products_id=$2&#38;% last; rewrite “^(.*)-c-(.*).html” /index.php?cPath=$2&#38;% last; rewrite “^(.*)-m-(.*).html” /index.php?manufacturers_id=$2&#38;% last; rewrite “^(.*)-pi-(.*).html” /popup_image.php?pID=$2&#38;% last; rewrite “^(.*)-t-(.*).html” /articles.php?tPath=$2&#38;% last; rewrite “^(.*)-au-(.*).html” /articles.php?authors_id=$2&#38;% last; rewrite “^(.*)-a-(.*).html” /article_info.php?articles_id=$2&#38;% last; rewrite “^(.*)-pr-(.*).html” /product_reviews.php?products_id=$2&#38;% last; rewrite “^(.*)-pri-(.*).html” /product_reviews_info.php?products_id=$2&#38;% last; rewrite “^(.*)-i-(.*).html” /information.php?info_id=$2&#38;% last; rewrite “^(.*)-pm-([0-9]+).html” /info_pages.php?pages_id=$2&#38;% last; rewrite [...]]]></description>
			<content:encoded><![CDATA[<p>location / {<br />
 if (!-e $request_filename)<br />
 {<br />
rewrite “^(.*)-p-(.*).html” /product_info.php?products_id=$2%1;<br />
rewrite “^(.*)-p-(.*).html” /product_info.php?products_id=$2&amp;% last;<br />
rewrite “^(.*)-c-(.*).html” /index.php?cPath=$2&amp;% last;<br />
rewrite “^(.*)-m-(.*).html” /index.php?manufacturers_id=$2&amp;% last;<br />
rewrite “^(.*)-pi-(.*).html” /popup_image.php?pID=$2&amp;% last;<br />
rewrite “^(.*)-t-(.*).html” /articles.php?tPath=$2&amp;% last;<br />
rewrite “^(.*)-au-(.*).html” /articles.php?authors_id=$2&amp;% last;<br />
rewrite “^(.*)-a-(.*).html” /article_info.php?articles_id=$2&amp;% last;<br />
rewrite “^(.*)-pr-(.*).html” /product_reviews.php?products_id=$2&amp;% last;<br />
rewrite “^(.*)-pri-(.*).html” /product_reviews_info.php?products_id=$2&amp;% last;<br />
rewrite “^(.*)-i-(.*).html” /information.php?info_id=$2&amp;% last;<br />
rewrite “^(.*)-pm-([0-9]+).html” /info_pages.php?pages_id=$2&amp;% last;<br />
rewrite “^(.*)-links-(.*).html” /links.php?lPath=$2&amp;% last;<br />
rewrite “^(.*)-n-(.*).html” /newsdesk_info.php?newsdesk_id=$2&amp;% last;<br />
rewrite “^(.*)-nc-(.*).html” /newsdesk_index.php?newsPath=$2&amp;% last;<br />
rewrite “^(.*)-nri-(.*).html” /newsdesk_reviews_info.php?newsdesk_id=$2&amp;% last;<br />
rewrite “^(.*)-nra-(.*).html” /newsdesk_reviews_article.php?newsdesk_id=$2&amp;% last;<br />
rewrite “^(.*)-f-(.*).html” /faqdesk_info.php?faqdesk_id=$2&amp;% last;<br />
rewrite “^(.*)-fc-(.*).html” /faqdesk_index.php?faqPath=$2&amp;% last;<br />
rewrite “^(.*)-fri-(.*).html” /faqdesk_reviews_info.php?faqdesk_id=$2&amp;% last;<br />
rewrite “^(.*)-fra-(.*).html” /faqdesk_reviews_article.php?faqdesk_id=$2&amp;% last;<br />
 }<br />
}</p>
<p>相应的apache为：</p>
<p>RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2%1<br />
RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-c-(.*).html$ index.php?cPath=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-m-(.*).html$ index.php?manufacturers_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-pi-(.*).html$ popup_image.php?pID=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-t-(.*).html$ articles.php?tPath=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-au-(.*).html$ articles.php?authors_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-a-(.*).html$ article_info.php?articles_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-pr-(.*).html$ product_reviews.php?products_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-pri-(.*).html$ product_reviews_info.php?products_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-i-(.*).html$ information.php?info_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-pm-([0-9]+).html$ info_pages.php?pages_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-links-(.*).html$ links.php?lPath=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-n-(.*).html$ newsdesk_info.php?newsdesk_id=$2&amp;%{QUERY_STRING}</p>
<p>RewriteRule ^(.*)-nc-(.*).html$ newsdesk_index.php?newsPath=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-nri-(.*).html$ newsdesk_reviews_info.php?newsdesk_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-nra-(.*).html$ newsdesk_reviews_article.php?newsdesk_id=$2&amp;%{QUERY_STRING}</p>
<p>RewriteRule ^(.*)-f-(.*).html$ faqdesk_info.php?faqdesk_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-fc-(.*).html$ faqdesk_index.php?faqPath=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-fri-(.*).html$ faqdesk_reviews_info.php?faqdesk_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-fra-(.*).html$ faqdesk_reviews_article.php?faqdesk_id=$2&amp;%{QUERY_STRING}</p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/510.html" title="nginx详解">nginx详解</a> (0)</li><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/504.html" title="Nginx的WordPress配置">Nginx的WordPress配置</a> (0)</li><li>06/03/2009 -- <a href="http://www.crazylemon.net/php/416.html" title="Nginx的UrlRewrite配置">Nginx的UrlRewrite配置</a> (0)</li><li>11/07/2009 -- <a href="http://www.crazylemon.net/apache/2400.html" title="Apache mod_rewrite模块中RewriteCond和RewriteRule的指令格式">Apache mod_rewrite模块中RewriteCond和RewriteRule的指令格式</a> (6)</li><li>09/10/2009 -- <a href="http://www.crazylemon.net/apache/1796.html" title="Apache服务器wordpress设置永久连接后怎么去掉INDEX.PHP">Apache服务器wordpress设置永久连接后怎么去掉INDEX.PHP</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/nginx/620.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>bind() for address &#8217;127.0.0.1:9000&#8242; failed: Address already in use</title>
		<link>http://www.crazylemon.net/php/567.html</link>
		<comments>http://www.crazylemon.net/php/567.html#comments</comments>
		<pubDate>Sun, 07 Jun 2009 22:52:01 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[Gateway]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[php-fpm]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=567</guid>
		<description><![CDATA[今天一台服务器又当了，因为php-fpm.log又写满2G，这个log文件一直在狂写，不知道什么原因，有空得查一下 服务器  502 Bad Gateway 删了php-fpm.log，重启php-fpm /usr/local/php/sbin/php-fpm restart 没用，报错： Shutting down php_fpm /usr/local/php/sbin/php-fpm: line 69: kill: (5899) &#8211; No such process 原来已经没有这个进程 /usr/local/php/sbin/php-fpm start 虽然提示：Starting php_fpm  done 但还是没启动成功，依然是502 Bad Gateway 查看日志文件：  [NOTICE] fpm_unix_init_main(), line 284: getrlimit(nofile): max:51200, cur:51200  [ERROR] fpm_sockets_new_listening_socket(), line 221: bind() for address &#8217;127.0.0.1:9000&#8242; failed: Address already in use (98)  原来127.0.0.1:9000端口被占用了 输入命令：netstat -ntlp，查看端口占用情况： [...]]]></description>
			<content:encoded><![CDATA[<p>今天一台服务器又当了，因为php-fpm.log又写满2G，这个log文件一直在狂写，不知道什么原因，有空得查一下</p>
<p>服务器  502 Bad Gateway</p>
<p>删了php-fpm.log，重启php-fpm</p>
<p>/usr/local/php/sbin/php-fpm restart</p>
<p>没用，报错：</p>
<p>Shutting down php_fpm /usr/local/php/sbin/php-fpm: line 69: kill: (5899) &#8211; No such process</p>
<p>原来已经没有这个进程</p>
<p>/usr/local/php/sbin/php-fpm start</p>
<p>虽然提示：Starting php_fpm  done</p>
<p>但还是没启动成功，依然是502 Bad Gateway</p>
<p>查看日志文件：</p>
<p> [NOTICE] fpm_unix_init_main(), line 284: getrlimit(nofile): max:51200, cur:51200<br />
 [ERROR] fpm_sockets_new_listening_socket(), line 221: bind() for address &#8217;127.0.0.1:9000&#8242; failed: Address already in use (98)</p>
<p> 原来127.0.0.1:9000端口被占用了</p>
<p>输入命令：netstat -ntlp，查看端口占用情况：</p>
<p>tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      19447/php-cgi</p>
<p>原来还有个php-cgi进程在跑</p>
<p>输入：killall php-cgi  杀掉所有 php-cgi 进程</p>
<p>然后启动 php-fpm :</p>
<p>/usr/local/php/sbin/php-fpm start</p>
<p>OK，成功了</p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>08/11/2009 -- <a href="http://www.crazylemon.net/nginx/1552.html" title="深究Nginx502 bad gateway, 504 Gateway Time-out的彻底解决（转）">深究Nginx502 bad gateway, 504 Gateway Time-out的彻底解决（转）</a> (0)</li><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/510.html" title="nginx详解">nginx详解</a> (0)</li><li>07/28/2009 -- <a href="http://www.crazylemon.net/linux/1389.html" title="linux 的计划任务 crond 服务">linux 的计划任务 crond 服务</a> (0)</li><li>07/18/2009 -- <a href="http://www.crazylemon.net/web/1239.html" title=".htaccess使用指南">.htaccess使用指南</a> (0)</li><li>02/11/2009 -- <a href="http://www.crazylemon.net/ftp/96.html" title="pure-ftpd.conf 中文说明">pure-ftpd.conf 中文说明</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/php/567.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx详解</title>
		<link>http://www.crazylemon.net/nginx/510.html</link>
		<comments>http://www.crazylemon.net/nginx/510.html#comments</comments>
		<pubDate>Sat, 06 Jun 2009 09:09:57 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Charset]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[Html]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[Link]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[rar]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[smtp]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[优化]]></category>
		<category><![CDATA[升级]]></category>
		<category><![CDATA[正则表达式]]></category>
		<category><![CDATA[虚拟主机]]></category>
		<category><![CDATA[配置]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=510</guid>
		<description><![CDATA[Nginx 概述   HTTP基础功能：   处理静态文件，索引文件以及自动索引；  反向代理加速(无缓存)，简单的负载均衡和容错；  FastCGI，简单的负载均衡和容错；  模块化的结构。过滤器包括gzipping, byte ranges, chunked responses, 以及 SSI-filter 。在SSI过滤器中，到同一个 proxy 或者 FastCGI 的多个子请求并发处理；  SSL 和 TLS SNI 支持；     IMAP/POP3 代理服务功能：   使用外部 HTTP 认证服务器重定向用户到 IMAP/POP3 后端；  使用外部 HTTP 认证服务器认证用户后连接重定向到内部的 SMTP 后端；  认证方法：   POP3: POP3 USER/PASS, APOP, AUTH LOGIN PLAIN CRAM-MD5;  IMAP: IMAP LOGIN;  SMTP: AUTH LOGIN PLAIN CRAM-MD5;  SSL [...]]]></description>
			<content:encoded><![CDATA[<p>Nginx 概述<br />
 </p>
<p>HTTP基础功能：  </p>
<p>处理静态文件，索引文件以及自动索引； <br />
反向代理加速(无缓存)，简单的负载均衡和容错； <br />
FastCGI，简单的负载均衡和容错； <br />
模块化的结构。过滤器包括gzipping, byte ranges, chunked responses, 以及 SSI-filter 。在SSI过滤器中，到同一个 proxy 或者 FastCGI 的多个子请求并发处理； <br />
SSL 和 TLS SNI 支持；  <br />
 </p>
<p>IMAP/POP3 代理服务功能：  </p>
<p>使用外部 HTTP 认证服务器重定向用户到 IMAP/POP3 后端； <br />
使用外部 HTTP 认证服务器认证用户后连接重定向到内部的 SMTP 后端； <br />
认证方法：  <br />
POP3: POP3 USER/PASS, APOP, AUTH LOGIN PLAIN CRAM-MD5; <br />
IMAP: IMAP LOGIN; <br />
SMTP: AUTH LOGIN PLAIN CRAM-MD5; <br />
SSL 支持； <br />
在 IMAP 和 POP3 模式下的 STARTTLS 和 STLS 支持；  <br />
支持的操作系统：  </p>
<p>FreeBSD 3.x, 4.x, 5.x, 6.x i386; FreeBSD 5.x, 6.x amd64; <br />
Linux 2.2, 2.4, 2.6 i386; Linux 2.6 amd64; <br />
Solaris 8 i386; Solaris 9 i386 and sun4u; Solaris 10 i386;<br />
MacOS X (10.4) PPC;<br />
结构与扩展：</p>
<p>一个主进程和多个工作进程。工作进程是单线程的，且不需要特殊授权即可运行；<br />
kqueue (FreeBSD 4.1+), epoll (Linux 2.6+), rt signals (Linux 2.2.19+), /dev/poll (Solaris 7 11/99+), select, 以及 poll 支持；<br />
kqueue支持的不同功能包括 EV_CLEAR, EV_DISABLE （临时禁止事件）， NOTE_LOWAT, EV_EOF, 有效数据的数目，错误代码；<br />
sendfile (FreeBSD 3.1+), sendfile (Linux 2.2+), sendfile64 (Linux 2.4.21+), 和 sendfilev (Solaris 8 7/01+) 支持；<br />
输入过滤 (FreeBSD 4.1+) 以及 TCP_DEFER_ACCEPT (Linux 2.4+) 支持；<br />
10,000 非活动的 HTTP keep-alive 连接仅需要 2.5M 内存。<br />
最小化的数据拷贝操作；<br />
其他HTTP功能：</p>
<p>基于IP 和名称的虚拟主机服务；<br />
Memcached 的 GET 接口；<br />
支持 keep-alive 和管道连接；<br />
灵活简单的配置；<br />
重新配置和在线升级而无须中断客户的工作进程；<br />
可定制的访问日志，日志写入缓存，以及快捷的日志回卷；<br />
4xx-5xx 错误代码重定向；<br />
基于 PCRE 的 rewrite 重写模块；<br />
基于客户端 IP 地址和 HTTP 基本认证的访问控制；<br />
PUT, DELETE, 和 MKCOL 方法；<br />
支持 FLV （Flash 视频）；<br />
带宽限制；<br />
实验特性：</p>
<p>内嵌的 perl<br />
通过 aio_read()/aio_write() 的套接字工作的实验模块，仅在 FreeBSD 下。<br />
对线程的实验化支持，FreeBSD 4.x 的实现基于 rfork()<br />
为什么选择Nginx<br />
 </p>
<p>Nginx 是一个高性能的 Web 和反向代理服务器, 它具有有很多非常优越的特性:</p>
<p>作为 Web 服务器：相比 Apache，Nginx 使用更少的资源，支持更多的并发连接，体现更高的效率，这点使 Nginx 尤其受到虚拟主机提供商的欢迎。能够支持高达 50,000 个并发连接数的响应，感谢 Nginx 为我们选择了 epoll and kqueue 作为开发模型.<br />
作为负载均衡服务器：Nginx 既可以在内部直接支持 Rails 和 PHP，也可以支持作为 HTTP代理服务器 对外进行服务。Nginx 用 C 编写, 不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好的多。<br />
作为邮件代理服务器: Nginx 同时也是一个非常优秀的邮件代理服务器（最早开发这个产品的目的之一也是作为邮件代理服务器），Last.fm 描述了成功并且美妙的使用经验。<br />
Nginx 安装非常的简单，配置文件 非常简洁（还能够支持perl语法），Bugs非常少的服务器: Nginx 启动特别容易，并且几乎可以做到7*24不间断运行，即使运行数个月也不需要重新启动。你还能够在 不间断服务的情况下进行软件版本的升级。<br />
安装Nginx<br />
 </p>
<p>预先编译好的安装包</p>
<p>Nginx在一些Linux发行版和BSD的各个变种版本的安装包仓库中都会有，通过各个系统自带的软件包管理方法即可安装。需要注意的是，很多预先编译好的安装包都比较陈旧，大多数情况下还是推荐直接从源码编译。</p>
<p> </p>
<p>官方源代码下载</p>
<p>点击下载源代码</p>
<p> </p>
<p>使用源代码进行构建</p>
<p>Nginx 使用 Unix 下常用的 &#8216;./configure &amp;&amp; make &amp;&amp; make install&#8217; 过程来编译安装。</p>
<p>configure 脚本确定系统所具有一些特性，特别是 nginx 用来处理连接的方法。然后，它创建 Makefile 文件。</p>
<p>configure 支持下面的选项：</p>
<p>&#8211;prefix=&lt;path&gt; &#8211; Nginx安装路径。如果没有指定，默认为 /usr/local/nginx。</p>
<p>&#8211;sbin-path=&lt;path&gt; &#8211; Nginx可执行文件安装路径。只能安装时指定，如果没有指定，默认为&lt;prefix&gt;/sbin/nginx。</p>
<p>&#8211;conf-path=&lt;path&gt; &#8211; 在没有给定-c选项下默认的nginx.conf的路径。如果没有指定，默认为&lt;prefix&gt;/conf/nginx.conf。</p>
<p>&#8211;pid-path=&lt;path&gt; &#8211; 在nginx.conf中没有指定pid指令的情况下，默认的nginx.pid的路径。如果没有指定，默认为 &lt;prefix&gt;/logs/nginx.pid。</p>
<p>&#8211;lock-path=&lt;path&gt; &#8211; nginx.lock文件的路径。</p>
<p>&#8211;error-log-path=&lt;path&gt; &#8211; 在nginx.conf中没有指定error_log指令的情况下，默认的错误日志的路径。如果没有指定，默认为 &lt;prefix&gt;/logs/error.log。</p>
<p>&#8211;http-log-path=&lt;path&gt; &#8211; 在nginx.conf中没有指定access_log指令的情况下，默认的访问日志的路径。如果没有指定，默认为 &lt;prefix&gt;/logs/access.log。</p>
<p>&#8211;user=&lt;user&gt; &#8211; 在nginx.conf中没有指定user指令的情况下，默认的nginx使用的用户。如果没有指定，默认为 nobody。</p>
<p>&#8211;group=&lt;group&gt; &#8211; 在nginx.conf中没有指定user指令的情况下，默认的nginx使用的组。如果没有指定，默认为 nobody。</p>
<p>&#8211;builddir=DIR &#8211; 指定编译的目录</p>
<p>&#8211;with-rtsig_module &#8211; 启用 rtsig 模块</p>
<p>&#8211;with-select_module &#8211;without-select_module &#8211; Whether or not to enable the select module. This module is enabled by default if a more suitable method such as kqueue, epoll, rtsig or /dev/poll is not discovered by configure.</p>
<p>//允许或不允许开启SELECT模式，如果 configure 没有找到更合适的模式，比如：kqueue(sun os),epoll (linux kenel 2.6+), rtsig(实时信号)或者/dev/poll(一种类似select的模式，底层实现与SELECT基本相 同，都是采用轮训方法) SELECT模式将是默认安装模式</p>
<p>&#8211;with-poll_module &#8211;without-poll_module &#8211; Whether or not to enable the poll module. This module is enabled by default if a more suitable method such as kqueue, epoll, rtsig or /dev/poll is not discovered by configure.</p>
<p>&#8211;with-http_ssl_module &#8211; Enable ngx_http_ssl_module. Enables SSL support and the ability to handle HTTPS requests. Requires OpenSSL. On Debian, this is libssl-dev.</p>
<p>//开启HTTP SSL模块，使NGINX可以支持HTTPS请求。这个模块需要已经安装了OPENSSL，在DEBIAN上是libssl</p>
<p>&#8211;with-http_realip_module &#8211; 启用 ngx_http_realip_module</p>
<p>&#8211;with-http_addition_module &#8211; 启用 ngx_http_addition_module</p>
<p>&#8211;with-http_sub_module &#8211; 启用 ngx_http_sub_module</p>
<p>&#8211;with-http_dav_module &#8211; 启用 ngx_http_dav_module</p>
<p>&#8211;with-http_flv_module &#8211; 启用 ngx_http_flv_module</p>
<p>&#8211;with-http_stub_status_module &#8211; 启用 “server status” 页</p>
<p>&#8211;without-http_charset_module &#8211; 禁用 ngx_http_charset_module</p>
<p>&#8211;without-http_gzip_module &#8211; 禁用 ngx_http_gzip_module. 如果启用，需要 zlib 。</p>
<p>&#8211;without-http_ssi_module &#8211; 禁用 ngx_http_ssi_module</p>
<p>&#8211;without-http_userid_module &#8211; 禁用 ngx_http_userid_module</p>
<p>&#8211;without-http_access_module &#8211; 禁用 ngx_http_access_module</p>
<p>&#8211;without-http_auth_basic_module &#8211; 禁用 ngx_http_auth_basic_module</p>
<p>&#8211;without-http_autoindex_module &#8211; 禁用 ngx_http_autoindex_module</p>
<p>&#8211;without-http_geo_module &#8211; 禁用 ngx_http_geo_module</p>
<p>&#8211;without-http_map_module &#8211; 禁用 ngx_http_map_module</p>
<p>&#8211;without-http_referer_module &#8211; 禁用 ngx_http_referer_module</p>
<p>&#8211;without-http_rewrite_module &#8211; 禁用 ngx_http_rewrite_module. 如果启用需要 PCRE 。</p>
<p>&#8211;without-http_proxy_module &#8211; 禁用 ngx_http_proxy_module</p>
<p>&#8211;without-http_fastcgi_module &#8211; 禁用 ngx_http_fastcgi_module</p>
<p>&#8211;without-http_memcached_module &#8211; 禁用 ngx_http_memcached_module</p>
<p>&#8211;without-http_limit_zone_module &#8211; 禁用 ngx_http_limit_zone_module</p>
<p>&#8211;without-http_empty_gif_module &#8211; 禁用 ngx_http_empty_gif_module</p>
<p>&#8211;without-http_browser_module &#8211; 禁用 ngx_http_browser_module</p>
<p>&#8211;without-http_upstream_ip_hash_module &#8211; 禁用 ngx_http_upstream_ip_hash_module</p>
<p>&#8211;with-http_perl_module &#8211; 启用 ngx_http_perl_module</p>
<p>&#8211;with-perl_modules_path=PATH &#8211; 指定 perl 模块的路径</p>
<p>&#8211;with-perl=PATH &#8211; 指定 perl 执行文件的路径</p>
<p>&#8211;http-log-path=PATH &#8211; Set path to the http access log</p>
<p>&#8211;http-client-body-temp-path=PATH &#8211; Set path to the http client request body temporary files</p>
<p>&#8211;http-proxy-temp-path=PATH &#8211; Set path to the http proxy temporary files</p>
<p>&#8211;http-fastcgi-temp-path=PATH &#8211; Set path to the http fastcgi temporary files</p>
<p>&#8211;without-http &#8211; 禁用 HTTP server</p>
<p>&#8211;with-mail &#8211; 启用 IMAP4/POP3/SMTP 代理模块</p>
<p>&#8211;with-mail_ssl_module &#8211; 启用 ngx_mail_ssl_module</p>
<p>&#8211;with-cc=PATH &#8211; 指定 C 编译器的路径</p>
<p>&#8211;with-cpp=PATH &#8211; 指定 C 预处理器的路径</p>
<p>&#8211;with-cc-opt=OPTIONS &#8211; Additional parameters which will be added to the variable CFLAGS. With the use of the system library PCRE in FreeBSD, it is necessary to indicate &#8211;with-cc-opt=”-I /usr/local/include”. If we are using select() and it is necessary to increase the number of file descriptors, then this also can be assigned here: &#8211;with-cc-opt=”-D FD_SETSIZE=2048&#8243;.</p>
<p>&#8211;with-ld-opt=OPTIONS &#8211; Additional parameters passed to the linker. With the use of the system library PCRE in FreeBSD, it is necessary to indicate &#8211;with-ld-opt=”-L /usr/local/lib”.</p>
<p>&#8211;with-cpu-opt=CPU &#8211; 为特定的 CPU 编译，有效的值包括：pentium, pentiumpro, pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64, ppc64</p>
<p>&#8211;without-pcre &#8211; 禁止 PCRE 库的使用。同时也会禁止 HTTP rewrite 模块。在 “location” 配置指令中的正则表达式也需要 PCRE 。</p>
<p>&#8211;with-pcre=DIR &#8211; 指定 PCRE 库的源代码的路径。</p>
<p>&#8211;with-pcre-opt=OPTIONS &#8211; Set additional options for PCRE building.</p>
<p>&#8211;with-md5=DIR &#8211; Set path to md5 library sources.</p>
<p>&#8211;with-md5-opt=OPTIONS &#8211; Set additional options for md5 building.</p>
<p>&#8211;with-md5-asm &#8211; Use md5 assembler sources.</p>
<p>&#8211;with-sha1=DIR &#8211; Set path to sha1 library sources.</p>
<p>&#8211;with-sha1-opt=OPTIONS &#8211; Set additional options for sha1 building.</p>
<p>&#8211;with-sha1-asm &#8211; Use sha1 assembler sources.</p>
<p>&#8211;with-zlib=DIR &#8211; Set path to zlib library sources.</p>
<p>&#8211;with-zlib-opt=OPTIONS &#8211; Set additional options for zlib building.</p>
<p>&#8211;with-zlib-asm=CPU &#8211; Use zlib assembler sources optimized for specified CPU, valid values are: pentium, pentiumpro</p>
<p>&#8211;with-openssl=DIR &#8211; Set path to OpenSSL library sources</p>
<p>&#8211;with-openssl-opt=OPTIONS &#8211; Set additional options for OpenSSL building</p>
<p>&#8211;with-debug &#8211; 启用调试日志</p>
<p>&#8211;add-module=PATH &#8211; Add in a third-party module found in directory PATH</p>
<p>在不同版本间，选项可能会有些许变化，请总是使用 ./configure &#8211;help 命令来检查一下当前的选项列表。</p>
<p>示例 (最好能在同一行)：</p>
<p> </p>
<p>    ./configure \        &#8211;sbin-path=/usr/local/nginx/nginx \        &#8211;conf-path=/usr/local/nginx/nginx.conf \        &#8211;pid-path=/usr/local/nginx/nginx.pid \        &#8211;with-http_ssl_module \        &#8211;with-pcre=../pcre-4.4 \        &#8211;with-zlib=../zlib-1.1.3<br />
 </p>
<p>Ubuntu/debian 上的示例，需要预先安装 libgcrypt11-dev, libpcre3-dev 和 libssl-dev (选择 &#8211;with-md5 或 &#8211;with-sha1 中的一个, 但不能都选; 在 debian 和 ubuntu 上, 它们应该都指向 /usr/lib)</p>
<p> </p>
<p>     ./configure &#8211;with-openssl=/usr/lib/ssl/ &#8211;with-md5=/usr/lib<br />
 </p>
<p>Ubuntu Edgy 的一个 0.5.2 版本的 .deb 包可以在这里下载: nginx_0.5.2-1_i386.deb.</p>
<p>(注: 根据 October 2006 message 的消息，md5 在一个现在不再使用的 http 缓存模块中用到，而 sha1 用在一个未完成的 mysql 库模块，所以它们当前都不是必须的)</p>
<p> </p>
<p>运行和控制 Nginx &#8211; 命令行参数和信号<br />
不像许多其他软件系统，Nginx 仅有数个命令行参数，完全通过配置文件来配置（想象一下）。</p>
<p>选项<br />
示例<br />
使用信号加载新的配置<br />
平滑升级到新的二进制代码<br />
 </p>
<p> </p>
<p>选项</p>
<p>-c &lt;/path/to/config&gt; 为 Nginx 指定一个配置文件，来代替缺省的。</p>
<p>-t 不运行，而仅仅测试配置文件。nginx 将检查配置文件的语法的正确性，并尝试打开配置文件中所引用到的文件。</p>
<p>-v 显示 nginx 的版本。</p>
<p>-V 显示 nginx 的版本，编译器版本和配置参数。</p>
<p> </p>
<p>示例</p>
<p> </p>
<p>/usr/bin/nginx -t -c ~/mynginx.conf<br />
 </p>
<p> </p>
<p>通过系统的信号控制 Nginx</p>
<p>可以使用信号系统来控制主进程。默认，nginx 将其主进程的 pid 写入到 /usr/local/nginx/logs/nginx.pid 文件中。通过传递参数给 ./configure 或使用 pid 指令，来改变该文件的位置。</p>
<p>主进程可以处理以下的信号：</p>
<p>TERM, INT 快速关闭<br />
QUIT 从容关闭<br />
HUP 重载配置<br />
用新的配置开始新的工作进程<br />
从容关闭旧的工作进程<br />
USR1 重新打开日志文件<br />
USR2 平滑升级可执行程序。<br />
WINCH 从容关闭工作进程</p>
<p> </p>
<p>尽管你不必自己操作工作进程，但是，它们也支持一些信号：</p>
<p>TERM, INT 快速关闭<br />
QUIT 从容关闭<br />
USR1 重新打开日志文件</p>
<p> </p>
<p> </p>
<p>使用信号加载新的配置</p>
<p>Nginx 支持几个信号，能在它运行时控制其操作。其中最普通的是 15 ，用来中止运行的进程：</p>
<p> </p>
<p># ps aux | egrep &#8216;(PID|nginx)&#8217;USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMANDroot      2213  0.0  0.0   6784  2036 ?        Ss   03:01   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf<br />
# kill -15 2213<br />
 </p>
<p>而最有趣的是能平滑改变 nginx 配置的选项（请注意，在重载前，要先测试一下配置文件）：</p>
<p> </p>
<p># nginx -t -c /etc/nginx/nginx.conf2006/09/16 13:07:10 [info] 15686#0: the configuration file /etc/nginx/nginx.conf syntax is ok2006/09/16 13:07:10 [info] 15686#0: the configuration file /etc/nginx/nginx.conf was tested successfully<br />
# ps aux | egrep &#8216;(PID|nginx)&#8217;<br />
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND<br />
root      2213  0.0  0.0   6784  2036 ?        Ss   03:01   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf<br />
# kill -HUP 2213<br />
 </p>
<p>当 nginx 接收到 HUP 信号，它会尝试先解析配置文件（如果指定配置文件，就使用指定的，否则使用默认的），成功的话，就应用新的配置文件（例如：重新打开日志文件或监听的套接 字）。之后，nginx 运行新的工作进程并从容关闭旧的工作进程。通知工作进程关闭监听套接字但是继续为当前连接的客户提供服务。所有客户端的服务完成后，旧的工作进程被关闭。 如果新的配置文件应用失败，nginx 将继续使用旧的配置进行工作。</p>
<p> </p>
<p>平滑升级到新的二进制代码</p>
<p>你可以在不中断服务的情况下 &#8211; 新的请求也不会丢失，使用新的 nginx 可执行程序替换旧的（当升级新版本或添加/删除服务器模块时）。</p>
<p>首先，使用新的可执行程序替换旧的（最好做好备份），然后，发送 USR2 (kill -USR2 pid)信号给主进程。主进程将重命名它的 .pid 文件为 .oldbin (比如：/usr/local/nginx/logs/nginx.pid.oldbin)，然后执行新的可执行程序，依次启动新的主进程和新的工作进程：</p>
<p> </p>
<p>  PID  PPID USER    %CPU   VSZ WCHAN  COMMAND33126     1 root     0.0  1164 pause  nginx: master process /usr/local/nginx/sbin/nginx33134 33126 nobody   0.0  1368 kqread nginx: worker process (nginx)<br />
33135 33126 nobody   0.0  1380 kqread nginx: worker process (nginx)<br />
33136 33126 nobody   0.0  1368 kqread nginx: worker process (nginx)<br />
36264 33126 root     0.0  1148 pause  nginx: master process /usr/local/nginx/sbin/nginx<br />
36265 36264 nobody   0.0  1364 kqread nginx: worker process (nginx)<br />
36266 36264 nobody   0.0  1364 kqread nginx: worker process (nginx)<br />
36267 36264 nobody   0.0  1364 kqread nginx: worker process (nginx)<br />
 </p>
<p>在这时，两个 nginx 实例会同时运行，一起处理输入的请求。要逐步停止旧的实例，你必须发送 WINCH 信号给旧的主进程，然后，它的工作进程就将开始从容关闭：</p>
<p> </p>
<p>  PID  PPID USER    %CPU   VSZ WCHAN  COMMAND33126     1 root     0.0  1164 pause  nginx: master process /usr/local/nginx/sbin/nginx33135 33126 nobody   0.0  1380 kqread nginx: worker process is shutting down (nginx)<br />
36264 33126 root     0.0  1148 pause  nginx: master process /usr/local/nginx/sbin/nginx<br />
36265 36264 nobody   0.0  1364 kqread nginx: worker process (nginx)<br />
36266 36264 nobody   0.0  1364 kqread nginx: worker process (nginx)<br />
36267 36264 nobody   0.0  1364 kqread nginx: worker process (nginx)<br />
 </p>
<p>一段时间后，旧的工作进程处理了所有已连接的请求后退出，就仅由新的工作进程来处理输入的请求了：</p>
<p> </p>
<p>  PID  PPID USER    %CPU   VSZ WCHAN  COMMAND33126     1 root     0.0  1164 pause  nginx: master process /usr/local/nginx/sbin/nginx36264 33126 root     0.0  1148 pause  nginx: master process /usr/local/nginx/sbin/nginx<br />
36265 36264 nobody   0.0  1364 kqread nginx: worker process (nginx)<br />
36266 36264 nobody   0.0  1364 kqread nginx: worker process (nginx)<br />
36267 36264 nobody   0.0  1364 kqread nginx: worker process (nginx)<br />
 </p>
<p>这时，因为旧的服务器还尚未关闭它监听的套接字，所以，通过下面的几步，你仍可以恢复旧的服务器：</p>
<p>发送 HUP 信号给旧的主进程 &#8211; 它将在不重载配置文件的情况下启动它的工作进程<br />
发送 QUIT 信号给新的主进程，要求其从容关闭其工作进程<br />
发送 TERM 信号给新的主进程，迫使其退出<br />
如果因为某些原因新的工作进程不能退出，向其发送 KILL 信号<br />
新的主进程退出后，旧的主进程会由移除 .oldbin 前缀，恢复为它的 .pid 文件，这样，一切就都恢复到升级之前了。</p>
<p>如果尝试升级成功，而你也希望保留新的服务器时，发送 QUIT 信号给旧的主进程使其退出而只留下新的服务器运行：</p>
<p> </p>
<p>      PID  PPID USER    %CPU   VSZ WCHAN  COMMAND    36264     1 root     0.0  1148 pause  nginx: master process /usr/local/nginx/sbin/nginx    36265 36264 nobody   0.0  1364 kqread nginx: worker process (nginx)<br />
    36266 36264 nobody   0.0  1364 kqread nginx: worker process (nginx)<br />
    36267 36264 nobody   0.0  1364 kqread nginx: worker process (nginx)<br />
 </p>
<p>Nginx 配置优化<br />
hash表</p>
<p>Ngnix使用hash表来协助完成请求的快速处理。</p>
<p>考虑到保存键及其值的hash表存储单元的大小不至于超出设定参数(hash bucket size)， 在启动和每次重新配置时，Nginx为hash表选择尽可能小的尺寸。</p>
<p>直到hash表超过参数(hash max size)的大小才重新进行选择. 对于大多数hash表都有指令来修改这些参数。例如，保存服务器名字的hash表是由指令 server_names_hash_max_size 和 server_names_hash_bucket_size所 控制的。参数hash bucket size总是等于hash表的大小，并且是一路处理器缓存大小的倍数。在减少了在内存中的存取次数后，使在处理器中加速查找hash表键值成为可能。如果 hash bucket size等于一路处理器缓存的大小，那么在查找键的时候，最坏的情况下在内存中查找的次数为2。第一次是确定存储单元的地址，第二次是在存储单元中查找键 值。因此，如果Nginx给出需要增大 hash max size 或 hash bucket size的提示，那么首要的是增大前一个参数的大小.</p>
<p> </p>
<p>事件模型</p>
<p>Nginx支持如下处理连接的方法（I/O复用方法），这些方法可以通过use指令指定。</p>
<p>select &#8211; 标准方法。 如果当前平台没有更有效的方法，它是编译时默认的方法。你可以使用配置参数 &#8211;with-select_module 和 &#8211;without-select_module 来启用或禁用这个模块。<br />
poll &#8211; 标准方法。 如果当前平台没有更有效的方法，它是编译时默认的方法。你可以使用配置参数 &#8211;with-poll_module 和 &#8211;without-poll_module 来启用或禁用这个模块。<br />
kqueue &#8211; 高效的方法，使用于 FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 和 MacOS X. 使用双处理器的MacOS X系统使用kqueue可能会造成内核崩溃。<br />
epoll &#8211; 高效的方法，使用于Linux内核2.6版本及以后的系统。在某些发行版本中，如SuSE 8.2, 有让2.4版本的内核支持epoll的补丁。<br />
rtsig &#8211; 可执行的实时信号，使用于Linux内核版本2.2.19以后的系统。默认情况下整个系统中不能出现大于1024个POSIX实时(排队)信号。这种情况对于高负载的服务器来说是低效的；所以有必要通过调节内核参数 /proc/sys/kernel/rtsig-max 来增加队列的大小。可是从Linux内核版本2.6.6-mm2开始， 这个参数就不再使用了，并且对于每个进程有一个独立的信号队列，这个队列的大小可以用 RLIMIT_SIGPENDING 参数调节。当这个队列过于拥塞，nginx就放弃它并且开始使用 poll 方法来处理连接直到恢复正常。<br />
/dev/poll &#8211; 高效的方法，使用于 Solaris 7 11/99+, HP/UX 11.22+ (eventport), IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+.<br />
eventport &#8211; 高效的方法，使用于 Solaris 10. 为了防止出现内核崩溃的问题， 有必要安装 这个 安全补丁。<br />
 </p>
<p>参考：Nginx 中文站：http://www.nginx.cn/NginxChsFeatureRequests</p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>07/18/2009 -- <a href="http://www.crazylemon.net/web/1239.html" title=".htaccess使用指南">.htaccess使用指南</a> (0)</li><li>05/28/2009 -- <a href="http://www.crazylemon.net/nginx/211.html" title="Nginx服务器安装Magento">Nginx服务器安装Magento</a> (1)</li><li>02/07/2009 -- <a href="http://www.crazylemon.net/nginx/74.html" title="nginx配置详细说明">nginx配置详细说明</a> (0)</li><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/504.html" title="Nginx的WordPress配置">Nginx的WordPress配置</a> (0)</li><li>02/11/2009 -- <a href="http://www.crazylemon.net/ftp/96.html" title="pure-ftpd.conf 中文说明">pure-ftpd.conf 中文说明</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/nginx/510.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

