<?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>Hello, SA &#187; nginx</title>
	<atom:link href="http://blog.helosa.org/tag/nginx/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.helosa.org</link>
	<description>Linux System Administrator</description>
	<lastBuildDate>Tue, 31 Jan 2012 08:28:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>基于wp 的blog 遭遇一次自杀式攻击</title>
		<link>http://blog.helosa.org/2011/07/03/blog-wordpress.html</link>
		<comments>http://blog.helosa.org/2011/07/03/blog-wordpress.html#comments</comments>
		<pubDate>Sun, 03 Jul 2011 08:58:04 +0000</pubDate>
		<dc:creator>Chan Cham Chung</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://blog.helosa.org/?p=414</guid>
		<description><![CDATA[微博的名人确实有杀伤力啊，周五的时候，Kaifu 老师的微博转了一下公司的博客地址，结果访问一下子涌过来了。5000 的访问里有3000+ 是访问 / ，wp 的 / 是动态的啊，难怪撑不住，load1m 飙到50 ，20 个php-fpm 忙得不行。我把这类都归结于自杀式攻击，其实，很多时候，弄死我们的，都是自己啊。 解决也不是很难，静态化吧。curl 一个首页放到wp 的文件夹里，命名为 index.htm ，顺便改改 nginx 的配置： if ($uri = &#8220;/&#8221;){ rewrite &#8220;^/$&#8221; /index.htm break ; } 完事，load1m 迅速下降到1 以下了。 处理这个事情的时候我正在打火锅呢，其实还想做得更完美一点的，静态化的首页，也能定时更新一下，但发现没那么简单，就放弃了。就放下去吃火锅了，天杀的谁想出来在这么热的天时吃火锅的！！ 其实最好的做法就是，用 wp 的 wp super cache 插件。]]></description>
			<content:encoded><![CDATA[<p>微博的名人确实有杀伤力啊，周五的时候，Kaifu 老师的微博转了一下公司的博客地址，结果访问一下子涌过来了。5000 的访问里有3000+ 是访问 / ，wp 的 / 是动态的啊，难怪撑不住，load1m 飙到50 ，20 个php-fpm 忙得不行。我把这类都归结于自杀式攻击，其实，很多时候，弄死我们的，都是自己啊。</p>
<p>解决也不是很难，静态化吧。curl 一个首页放到wp 的文件夹里，命名为 index.htm ，顺便改改 nginx 的配置：</p>
<div id="_mcePaste">if ($uri = &#8220;/&#8221;){</div>
<div id="_mcePaste">rewrite &#8220;^/$&#8221; /index.htm break ;</div>
<div id="_mcePaste">}</div>
<div></div>
<div>完事，load1m 迅速下降到1 以下了。</div>
<p>处理这个事情的时候我正在打火锅呢，其实还想做得更完美一点的，静态化的首页，也能定时更新一下，但发现没那么简单，就放弃了。就放下去吃火锅了，天杀的谁想出来在这么热的天时吃火锅的！！</p>
<p>其实最好的做法就是，用 wp 的 wp super cache 插件。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.helosa.org/2011/07/03/blog-wordpress.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx+apache+dav_svn 的怪异问题</title>
		<link>http://blog.helosa.org/2011/07/03/nginx-apache-dav_svn.html</link>
		<comments>http://blog.helosa.org/2011/07/03/nginx-apache-dav_svn.html#comments</comments>
		<pubDate>Sun, 03 Jul 2011 08:04:53 +0000</pubDate>
		<dc:creator>Chan Cham Chung</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[troubleshooting]]></category>

		<guid isPermaLink="false">http://blog.helosa.org/?p=408</guid>
		<description><![CDATA[最近帮朋友的网站做个小优化，由apache 迁移到nginx ，结果问题多多，svn 在提交的时候竟然有这个错误： $ svn ci -m&#8221;fix the mail problem &#8220; Sending        util.php svn: Commit failed (details follow): svn: File &#8216;util.php&#8217; is out of date svn: &#8216;/svn/!svn/bc/496/trunk/util.php&#8217; path not found 但是提交其它文件貌似没有问题。怪异到爆！！！ 首先说说nginx 的配置。 svn 仍然使用 apache 的dav_svn ，只是端口由80 改为 1234，其它配置不改。 location  /svn { proxy_pass http://127.0.0.1:1234 ; proxy_set_header Host &#8220;svn.mysite.net&#8221; ; } [...]]]></description>
			<content:encoded><![CDATA[<p>最近帮朋友的网站做个小优化，由apache 迁移到nginx ，结果问题多多，svn 在提交的时候竟然有这个错误：</p>
<div id="_mcePaste">$ svn ci -m&#8221;fix the mail problem &#8220;</div>
<div id="_mcePaste">Sending        util.php</div>
<div id="_mcePaste">svn: Commit failed (details follow):</div>
<div id="_mcePaste">svn: File &#8216;util.php&#8217; is out of date</div>
<div id="_mcePaste">svn: &#8216;/svn/!svn/bc/496/trunk/util.php&#8217; path not found</div>
<div>但是提交其它文件貌似没有问题。怪异到爆！！！</div>
<p>首先说说nginx 的配置。</p>
<p>svn 仍然使用 apache 的dav_svn ，只是端口由80 改为 1234，其它配置不改。</p>
<p>location  /svn {</p>
<p>proxy_pass http://127.0.0.1:1234 ;</p>
<p>proxy_set_header Host &#8220;svn.mysite.net&#8221; ;</p>
<p>}</p>
<div>终于在google 大神找到一篇俄文的mailing-list（http://www.lexa.ru/nginx-ru/msg39625.html），竟然有人和我同样的错误，也终于弄清楚什么事了。。。简直是自己白痴！！</div>
<div>我的php 的配置：</div>
<div>
<div>location ~ \.php$ {</div>
<div>root           /var/www/backend/  ;</div>
<div>fastcgi_pass   127.0.0.1:9000;</div>
<div>fastcgi_index  index.php;</div>
<div>include        fastcgi.conf;</div>
<div>}</div>
</div>
<div>这个location 用了正则匹配，比svn 的普通location 优先级高，结果svn 提交util.php 的时候（会发送一堆svn 的指令如propfind , option 等），优先到php 的location 里，结果就出错了。。。</div>
<div>那svn 也用高优先级的location 匹配吧，修改一下，用前缀匹配：</div>
<div>location ^~ /svn</div>
<div>ok , 成功了。。。</div>
<div>事后我才看到，nginx 本身就有一个404 的log ：</div>
<div>211.102.143.12 &#8211; hello [03/Jul/2011:15:34:53 +0800] &#8220;PROPFIND /svn/!svn/bc/496/trunk/util.php HTTP/1.1&#8243; 404 31 &#8220;-&#8221; &#8220;SVN/1.6.15 (r1038135) neon/0.28.6&#8243; &#8220;-&#8221;</div>
<div>唉。。。怪自己～～</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.helosa.org/2011/07/03/nginx-apache-dav_svn.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>一个关于cookie 的怪异登陆问题</title>
		<link>http://blog.helosa.org/2011/06/02/cookie-login-fail.html</link>
		<comments>http://blog.helosa.org/2011/06/02/cookie-login-fail.html#comments</comments>
		<pubDate>Thu, 02 Jun 2011 11:38:12 +0000</pubDate>
		<dc:creator>Chan Cham Chung</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://blog.helosa.org/?p=403</guid>
		<description><![CDATA[近来有一些用户在某些网络环境下，登陆不了网站。通过详细的联系沟通，终于得出了结论。用户自己用http analyzer ，我在服务器端抓包。 用户端的请求头： GET / HTTP/1.1 Accept:application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, / Referer:http://www.zhihu.com/ Accept-Language:zh-CN User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0) UA-CPU:AMD64 Host:www.zhihu.com Connection:Keep-Alive Cache-Control:no-cache Cookie:***** 我抓包得到的请求头： GET / HTTP/1.1 Host: www.zhihu.com Connection: keep-alive User-Agent: Mozilla/4.0 [...]]]></description>
			<content:encoded><![CDATA[<p>近来有一些用户在某些网络环境下，登陆不了网站。通过详细的联系沟通，终于得出了结论。用户自己用http analyzer ，我在服务器端抓包。</p>
<p>用户端的请求头：</p>
<div id="_mcePaste">GET / HTTP/1.1</div>
<div id="_mcePaste">Accept:application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, /</div>
<div id="_mcePaste">Referer:http://www.zhihu.com/</div>
<div id="_mcePaste">Accept-Language:zh-CN</div>
<div id="_mcePaste">User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)</div>
<div id="_mcePaste">UA-CPU:AMD64</div>
<div id="_mcePaste">Host:www.zhihu.com</div>
<div id="_mcePaste">Connection:Keep-Alive</div>
<div id="_mcePaste">Cache-Control:no-cache</div>
<div id="_mcePaste">Cookie:*****</div>
<div></div>
<div>我抓包得到的请求头：</div>
<div>
<div>GET / HTTP/1.1</div>
<div>Host: www.zhihu.com</div>
<div>Connection: keep-alive</div>
<div>User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)</div>
<div>Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5</div>
<div>Qtnddkdrcx: zojajzrgfrdigltciezwhgoumzevhyzqexwfsgkkoyhpiyctzvwzbqzscjzqpuqrflttgfcuxuvzvfiurfjaojmgmenvrfgnqfolulvapnmnjhetvsmktvpdxxekebsrnnnzokqnyuesfldfpbgwcivwgmmjfkgtilacaixdlpibhhvckjbbsupufbjxbhuizwfuhfvyarrowwvipbzmvrh</div>
<div>Accept-Language: zh-CN,zh;q=0.8</div>
<div>Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3</div>
<div>Accept-Encoding: gzip,deflate,sdch</div>
<div>Cookie:</div>
<div>Cookie: *****</div>
</div>
<p>哇塞，基本全改了，除了cookie 也是那个，不过，多了一行空的cookie 。这是一个什么网络啊！！还加了一串不知道是什么的东西。</p>
<p>我测试了一下，nginx 是可以把 $http_cookie 正确读取出来的，但是后端的web 读取不了，读取了第一个空的cookie 。结果，一直认为用户没有cookie ，所以，用户就不能登陆了。</p>
<p>nginx 针对这种情况修复一下，在所有使用proxy_pass 的地方，加一行：</p>
<p>proxy_set_header Cookie $http_cookie ;</p>
<p>这样就把cookie 硬塞给后端了。</p>
<p>很不负责任地讲一句，我怀疑是运营商做的手脚。当然，也有可能是该用户的上网环境导致。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.helosa.org/2011/06/02/cookie-login-fail.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>亚运赛事系统架构探索</title>
		<link>http://blog.helosa.org/2010/12/20/info-2010-163-com-architecture.html</link>
		<comments>http://blog.helosa.org/2010/12/20/info-2010-163-com-architecture.html#comments</comments>
		<pubDate>Sun, 19 Dec 2010 16:35:09 +0000</pubDate>
		<dc:creator>Chan Cham Chung</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[haproxy]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[squid]]></category>

		<guid isPermaLink="false">http://blog.helosa.org/?p=368</guid>
		<description><![CDATA[广州亚运亚残在今天落幕了，一班亚运的同事将要离职，真让人伤感。随便写篇东西纪念一下我为亚运付出的一个月。 亚运赛事系统最初的系统架构，非常简单，就是前端用一堆组了lvs 的 squid 作为cache server ，后端跑nginx+resin 。 这个架构，优点就是够简单，如果cache server 不够，就横向扩展，同样简单。 但是，当整个系统的瓶颈不在缓存端时，缺点也很明显了。我发现，后端的load 很容易跑高，特点就是，缓存时间比较短（1 分钟），然后前端的穿透较多，再且，前端的访问很散列，并没有特别的热点。这样，如果作横向扩展，只会对后端的压力越大，因为穿透更多了。 之前去听SACC 2010 的，其实很多公司都用了一层haproxy 做 url hash 。于是，就对现有的架构作一次调整，希望对当时的负载情况有所帮助。 调整后的架构是这样的：最前端是一堆组了lvs 的haproxy ，作用是url hash 到后端的cache 。nginx 其实也是可以做url hash 的，在这里，选择nginx 还是 haproxy 呢，功能上nginx 确实稍胜一筹，但性能上 haproxy 也略优，选择什么也可以按个人爱好来定。呵呵。cache server 端，我也做了小调整，因为不需要只使用一个80 端口了，我一台服务器上跑两个squid 。用taskset 把2 个squid 绑定到cpu1 和 cpu2（默认都是cpu0 ） ，让cpu0 处理系统调用，cpu3 处理网络io 。一台4G 的服务器，在这个情况下已经算是把服务器使用得很尽了。cachedir 一律使用内存分区，不要出现磁盘io 。 但这个架构也不是绝对无敌，url hash [...]]]></description>
			<content:encoded><![CDATA[<p>广州亚运亚残在今天落幕了，一班亚运的同事将要离职，真让人伤感。随便写篇东西纪念一下我为亚运付出的一个月。</p>
<p>亚运赛事系统最初的系统架构，非常简单，就是前端用一堆组了lvs 的 squid 作为cache server ，后端跑nginx+resin 。</p>
<p>这个架构，优点就是够简单，如果cache server 不够，就横向扩展，同样简单。</p>
<p>但是，当整个系统的瓶颈不在缓存端时，缺点也很明显了。我发现，后端的load 很容易跑高，特点就是，缓存时间比较短（1 分钟），然后前端的穿透较多，再且，前端的访问很散列，并没有特别的热点。这样，如果作横向扩展，只会对后端的压力越大，因为穿透更多了。</p>
<p>之前去听SACC 2010 的，其实很多公司都用了一层haproxy 做 url hash 。于是，就对现有的架构作一次调整，希望对当时的负载情况有所帮助。</p>
<p>调整后的架构是这样的：最前端是一堆组了lvs 的haproxy ，作用是url hash 到后端的cache 。nginx 其实也是可以做url hash 的，在这里，选择nginx 还是 haproxy 呢，功能上nginx 确实稍胜一筹，但性能上 haproxy 也略优，选择什么也可以按个人爱好来定。呵呵。cache server 端，我也做了小调整，因为不需要只使用一个80 端口了，我一台服务器上跑两个squid 。用taskset 把2 个squid 绑定到cpu1 和 cpu2（默认都是cpu0 ） ，让cpu0 处理系统调用，cpu3 处理网络io 。一台4G 的服务器，在这个情况下已经算是把服务器使用得很尽了。cachedir 一律使用内存分区，不要出现磁盘io 。</p>
<p>但这个架构也不是绝对无敌，url hash 最怕遇到热点，特别热那种，就像110米跨栏决赛和男篮决赛。因为单一的url 并发过高，而导致其中一个cache server 跑满了一个cpu（url hash 把这个url 都调度到这个cache ） ，众所周知，squid 只能使用一个cpu ，这个cpu 跑满载了，请求就会开始阻塞了。然后连接数不断彪高，直接导致了前端的haproxy 也挂了，同时骨牌效应，所有的haproxy 都挂了。。。无奈，只好针对这个url 做特殊处理，rr 分配到后端多个squid ，而不走url hash 了。真是害人不浅阿。。。如果可以预先知道将会是热点的url ，这个问题将会更好解决，而不是要到haproxy 挂了才去处理。</p>
<p>末了，贴一下haproxy 的url hash 配置吧：</p>
<p>global<br />
log 127.0.0.1  local3 notice<br />
ulimit-n 409600<br />
maxconn 102400<br />
chroot /home/haproxy<br />
pidfile /home/haproxy/var/haproxy.pid<br />
user haproxy<br />
group haproxy<br />
nbproc  4<br />
daemon<br />
quiet</p>
<p>defaults<br />
log     global<br />
mode    http<br />
option  httplog<br />
option  dontlognull<br />
option  redispatch<br />
option  forwardfor<br />
option  httpclose<br />
option  log-separate-errors<br />
monitor-uri /do_not_delete/monitor.txt<br />
retries 3<br />
stats   uri     /haproxy-status<br />
maxconn         102400<br />
contimeout      5000<br />
clitimeout      50000<br />
srvtimeout      50000<br />
stats   auth    admin:123456</p>
<p>frontend http_server<br />
bind :80<br />
default_backend info_cache<br />
acl url_static path_end BKM400101.json<br />
use_backend info_cache_temp if url_static</p>
<p>backend info_cache<br />
option httpchk HEAD /live.js HTTP/1.1\r\nHost:\ info.2010.163.com<br />
balance uri len 15                            # url hash<br />
server  inst1 192.168.51.1:3128 check inter 5000 fall 3<br />
server  inst2 192.168.51.1:3129 check inter 5000 fall 3<br />
server  inst3 192.168.51.2:3128 check inter 5000 fall 3<br />
server  inst4 192.168.51.2:3129 check inter 5000 fall 3<br />
server  inst5 192.168.51.3:3128 check inter 5000 fall 3<br />
server  inst6 192.168.51.3:3129 check inter 5000 fall 3</p>
<p>backend info_cache_temp<br />
option httpchk HEAD /live.js HTTP/1.1\r\nHost:\ info.2010.163.com<br />
balance roundrobin                            # rr<br />
server  inst1 192.168.51.1:3128 check inter 5000 fall 3<br />
server  inst2 192.168.51.1:3129 check inter 5000 fall 3<br />
server  inst3 192.168.51.2:3128 check inter 5000 fall 3<br />
server  inst4 192.168.51.2:3129 check inter 5000 fall 3<br />
server  inst5 192.168.51.3:3128 check inter 5000 fall 3<br />
server  inst6 192.168.51.3:3129 check inter 5000 fall 3</p>
<p>其实这个架构只是一个调优，如果整套系统需要优化的话，还是需要从最初的设计入手，很多细节都要顾及。</p>
<p>细节包括，那些数据传输的地址，不要使用163.com 的，因为带了很大串的cookie ，用户每一次访问都带有这么一大串，是很占带宽的。还有根据不同的文件设置不同的缓存，这个最初没有设计好的话，js , css 等文件就混入到163.com 的域名中难以隔离。还需要根据具体的业务去配置一下缓存。业务数据，一定要从一开始就要有系统地收集统计，调优后对比分析。等等等等。。。</p>
<p>在这个架构下，前面的haproxy 只是纯代理，后面的cache server ，可以任意选择，经典一点的，可以用 squid 。或者上varnish ，再或者试用 ATS 。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.helosa.org/2010/12/20/info-2010-163-com-architecture.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用了nginx proxy_cache 引起的io 阻塞</title>
		<link>http://blog.helosa.org/2010/12/17/nginx-proxy_cache-io.html</link>
		<comments>http://blog.helosa.org/2010/12/17/nginx-proxy_cache-io.html#comments</comments>
		<pubDate>Thu, 16 Dec 2010 16:03:37 +0000</pubDate>
		<dc:creator>Chan Cham Chung</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[troubleshooting]]></category>

		<guid isPermaLink="false">http://blog.helosa.org/?p=363</guid>
		<description><![CDATA[这几天一直忙于解决各类莫名其妙的问题，今天遇到一个使用了nginx proxy_cache 的机器，io 出奇地高，简单处理了一下，简单记录下，没有太详细的数据。 这个nginx 的前面是一堆squid ，它作为一个二级缓存，这样对后端是很有好处的。 开发的同事说，这台机器使用了 proxy_cache 后，io 压力很大。 我粗略分析了一下，分析结果如下： #vmstat 1 procs &#8212;&#8212;&#8212;&#8211;memory&#8212;&#8212;&#8212;- &#8212;swap&#8211; &#8212;&#8211;io&#8212;- -system&#8211; &#8212;-cpu&#8212;- r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa 0  7     68  52720 437416 1325168    0 [...]]]></description>
			<content:encoded><![CDATA[<p>这几天一直忙于解决各类莫名其妙的问题，今天遇到一个使用了nginx proxy_cache 的机器，io 出奇地高，简单处理了一下，简单记录下，没有太详细的数据。</p>
<p>这个nginx 的前面是一堆squid ，它作为一个二级缓存，这样对后端是很有好处的。</p>
<p>开发的同事说，这台机器使用了 proxy_cache 后，io 压力很大。</p>
<p>我粗略分析了一下，分析结果如下：</p>
<p>#vmstat 1</p>
<div id="_mcePaste">procs &#8212;&#8212;&#8212;&#8211;memory&#8212;&#8212;&#8212;- &#8212;swap&#8211; &#8212;&#8211;io&#8212;- -system&#8211; &#8212;-cpu&#8212;-</div>
<div id="_mcePaste">r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa</div>
<div id="_mcePaste">0  7     68  52720 437416 1325168    0    0     1     2    2    2  0  0 10  1</div>
<div id="_mcePaste">0  7     68  51916 437528 1325848    0    0     0  4000 2812 2737  0  2 6  90</div>
<div id="_mcePaste">0  7     68  51868 437624 1325644    0    0     8  3040 2808 2705  1  2 0  99</div>
<div id="_mcePaste">0  7     68  52540 437596 1325068    0    0     8     510 3040 2841  0  1 1  97</div>
<div id="_mcePaste">0  7     68  51668 437700 1325964    0    0    60     4033 3479 3220  1  2 5  90</div>
<p>可以看到procs 栏处于b 状态的很多，一般情况下是io 阻塞了</p>
<p>#ps aux</p>
<p>nobody   32622  1.1  0.6 530236 19248 ?        D    23:31   0:12 nginx: worker process</p>
<p>nobody   32623  0.9  0.6 530136 19064 ?        D    23:31   0:10 nginx: worker process</p>
<p>nobody   32624  0.9  0.6 530372 19276 ?        D    23:31   0:09 nginx: worker process</p>
<p>nobody   32625  1.1  0.6 530332 19296 ?        D    23:31   0:11 nginx: worker process</p>
<p>看下nginx worker 的状态，全是D，请求资源阻塞了？</p>
<p>#iostat -x 1</p>
<p>avg-cpu:  %user   %nice %system %iowait  %steal   %idle</p>
<p>0.00    0.00    0.00   16.16    0.00   83.84</p>
<p>Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util</p>
<p>sda               0.00     8.00  0.00 15.00     0.00   184.00    12.27     0.58   38.67   4.53   6.80</p>
<p>sdb               0.00   611.00  0.00 308.00     0.00  7200.00    23.38    98.31  193.23   2.27  70.00</p>
<p>粗略算一下，峰值io ，也就200r + 100w /s ，对于nginx 来说，这个应该算是中等，不算很高。但 %util 经常在 100.00 左右徘徊，这个就有点异常了。</p>
<p>看看配置吧，改改调调，发现引起问题的是以下这段配置</p>
<p>proxy_cache_path  /data/cache/proxy_cache_dir levels=2:2:2 keys_zone=cache_one:500m inactive=5d max_size=200g;</p>
<p>levels = 2:2:2</p>
<p>也就是nginx 那些缓存下来的文件，会存放到 $CACHE_PATH/[0-9a-f][0-9a-f]/[0-9a-f][0-9a-f]/[0-9a-f][0-9a-f]/xxxxxxxxxxxxxxxxxxxx 里</p>
<p>猜想，会不会是目录层次太多了呢？</p>
<p>改之，levels = 2:2</p>
<p>这里有个重点，改了nginx 配置还不能根治，还需要重建缓存目录。</p>
<p>改完，load 下来了，完成。</p>
<p>其实io 优化的最根本还是用内存分区，不会有io 阻塞。不过我没时间看他的架构，把问题解决了就算了，留个坑给后人吧。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.helosa.org/2010/12/17/nginx-proxy_cache-io.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>零编码实现非办公网络http 验证</title>
		<link>http://blog.helosa.org/2010/11/18/home-office-http-auth.html</link>
		<comments>http://blog.helosa.org/2010/11/18/home-office-http-auth.html#comments</comments>
		<pubDate>Thu, 18 Nov 2010 07:36:27 +0000</pubDate>
		<dc:creator>Chan Cham Chung</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://blog.helosa.org/?p=348</guid>
		<description><![CDATA[有个需求，需要网站对非办公网络的访问进行验证，办公网络正常访问。 我山寨一下吧，没理由去改php 代码的。 不详说了，直接贴配置（别人贴代码我贴配置。。。） set $safe 0 ; location / { if ($http_x_forwarded_for ~ (x.x.x.x)&#124;(y.y.y.y)&#124;(z.z.z.z) ){set $safe 1;} if ( $cookie_bad_man = &#8220;x&#8221; ){ set $safe 1;} if ($safe = 0){rewrite &#8220;^.*$&#8221; http://wp.helosa.org/redirect/ redirect;} index index.html index.php; root /data/wordpress/; } location /redirect/ { charset utf-8 ; alias /data/redirect/; auth_basic &#8220;~oO-_-Oo~&#8221;; auth_basic_user_file  htpasswd; expires -1 ; [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">有个需求，需要网站对非办公网络的访问进行验证，办公网络正常访问。</div>
<div id="_mcePaste">我山寨一下吧，没理由去改php 代码的。</div>
<div id="_mcePaste">不详说了，直接贴配置（别人贴代码我贴配置。。。）</div>
<div id="_mcePaste">set $safe 0 ;</div>
<div id="_mcePaste">location / {</div>
<div id="_mcePaste">if ($http_x_forwarded_for ~ (x.x.x.x)|(y.y.y.y)|(z.z.z.z) ){set $safe 1;}</div>
<div id="_mcePaste">if ( $cookie_bad_man = &#8220;x&#8221; ){ set $safe 1;}</div>
<div id="_mcePaste">if ($safe = 0){rewrite &#8220;^.*$&#8221; http://wp.helosa.org/redirect/ redirect;}</div>
<div id="_mcePaste">index index.html index.php;</div>
<div id="_mcePaste">root /data/wordpress/;</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">location /redirect/ {</div>
<div id="_mcePaste">charset utf-8 ;</div>
<div id="_mcePaste">alias /data/redirect/;</div>
<div id="_mcePaste">auth_basic &#8220;~oO-_-Oo~&#8221;;</div>
<div id="_mcePaste">auth_basic_user_file  htpasswd;</div>
<div id="_mcePaste">expires -1 ;</div>
<div id="_mcePaste">set $bad_man &#8220;x&#8221;;</div>
<div id="_mcePaste">add_header &#8220;Set-Cookie&#8221; &#8220;bad_man=$bad_man ; path=/; domain=wp.helosa.org&#8221;;</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">原理是，如果x-forwarded-for （因为前面有代理）符合办公网络ip ，放行（set $safe 1）.</div>
<div id="_mcePaste">如果$safe 为0，跳转至 /redirect/ 目录</div>
<div id="_mcePaste">这个 /redirect/ 目录，设置http 验证，验证文件，用htpasswd 建一个吧</div>
<div id="_mcePaste">如果验证成功，set cookie ，主要是set 一个标示位，在这里是 bad_man ，当见到这个标志位的，也是放行的。</div>
<div id="_mcePaste">在 /redirect/ 下，有个index.html ，内容可以如下：</div>
<div id="_mcePaste">&lt;html&gt;&lt;body&gt;</div>
<div id="_mcePaste">&lt;meta http-equiv=&#8221;refresh&#8221; content=&#8221;0;url=http://wp.helosa.org/&#8221;&gt;</div>
<div id="_mcePaste">&lt;/body&gt;&lt;/html&gt;</div>
<div id="_mcePaste">主要用于跳转。</div>
<div id="_mcePaste">这样，就可以做到，办公网络不用验证，而在家访问，就要http 验证了。</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.helosa.org/2010/11/18/home-office-http-auth.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>个人主页上线</title>
		<link>http://blog.helosa.org/2010/08/01/homepage.html</link>
		<comments>http://blog.helosa.org/2010/08/01/homepage.html#comments</comments>
		<pubDate>Sat, 31 Jul 2010 16:06:56 +0000</pubDate>
		<dc:creator>Chan Cham Chung</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://blog.helosa.org/?p=294</guid>
		<description><![CDATA[开了个个人主页，全手工书写html ，且极其简洁，全英文。 http://www.helosa.org/ 写了个nginx module ，第一次写，纯练练手，业务有个需求，想用nginx module 来完成，就试着写一个来练习下先。 这个模块很简单，就是定义返回头的server 的值。以前lighttpd 有个 server.tag 的配置，就是差不多的用途的。 这个模块是在nginx 配置的 server 栏定义的，但直到使用时，我才发现，其实这个模块应该是放在main 那里才合适的。。。呃。。。算了，不改了！]]></description>
			<content:encoded><![CDATA[<p>开了个个人主页，全手工书写html ，且极其简洁，全英文。</p>
<p><a href="http://www.helosa.org/" target="_blank">http://www.helosa.org/</a></p>
<p>写了个nginx module ，第一次写，纯练练手，业务有个需求，想用nginx module 来完成，就试着写一个来练习下先。</p>
<p>这个模块很简单，就是定义返回头的server 的值。以前lighttpd 有个 server.tag 的配置，就是差不多的用途的。</p>
<p>这个模块是在nginx 配置的 server 栏定义的，但直到使用时，我才发现，其实这个模块应该是放在main 那里才合适的。。。呃。。。算了，不改了！</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.helosa.org/2010/08/01/homepage.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx-0.8.42 的一个新feature</title>
		<link>http://blog.helosa.org/2010/06/28/nginx-new-feature.html</link>
		<comments>http://blog.helosa.org/2010/06/28/nginx-new-feature.html#comments</comments>
		<pubDate>Sun, 27 Jun 2010 18:44:49 +0000</pubDate>
		<dc:creator>Chan Cham Chung</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://blog.helosa.org/?p=269</guid>
		<description><![CDATA[nginx 0.8.42 有个新功能： Feature: a text answer may be added to a &#8220;return&#8221; directive. (via nginx.org ) 这个功能其实很有趣，当然自己写也不难，官方实现了就最好。 找了下，找不到相关的配置说明，只好自己摸索一下吧。一试就出来了，真神奇，哈哈。 三步走（./configure ; make ; make install）安装好 nginx 后，在配置上加一段： location /iloveu/ { return 200 &#8220;iloveu&#8221; ; } 同时把 default_type  application/octet-stream; 修改为 default_type  text/plain; 如果是前者的话，不会看到字符串，而会下载的噢。 启动 nginx 后，curl -i http://127.0.0.1/iloveu/ HTTP/1.1 200 OK Server: nginx/0.8.42 Date: Sun, 27 [...]]]></description>
			<content:encoded><![CDATA[<p>nginx 0.8.42 有个新功能：</p>
<p>Feature: a text answer may be added to a &#8220;return&#8221; directive. (via nginx.org )</p>
<p>这个功能其实很有趣，当然自己写也不难，官方实现了就最好。</p>
<p>找了下，找不到相关的配置说明，只好自己摸索一下吧。一试就出来了，真神奇，哈哈。</p>
<p>三步走（./configure ; make ; make install）安装好 nginx 后，在配置上加一段：</p>
<div id="_mcePaste">location /iloveu/ {</div>
<div id="_mcePaste">return 200 &#8220;iloveu&#8221; ;</div>
<div id="_mcePaste">}</div>
<div>同时把</div>
<div>default_type  application/octet-stream;</div>
<div>修改为</div>
<div>default_type  text/plain;</div>
<div></div>
<div>如果是前者的话，不会看到字符串，而会下载的噢。</div>
<div>启动 nginx 后，curl -i http://127.0.0.1/iloveu/</div>
<div>
<div>HTTP/1.1 200 OK</div>
<div>Server: nginx/0.8.42</div>
<div>Date: Sun, 27 Jun 2010 18:44:04 GMT</div>
<div>Content-Type: text/plain</div>
<div>Content-Length: 3</div>
<div>Connection: keep-alive</div>
<div></div>
<div>iloveu</div>
</div>
<div>就这样玩玩吧。</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.helosa.org/2010/06/28/nginx-new-feature.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>debian 下nginx 快速搭建FCGI环境</title>
		<link>http://blog.helosa.org/2010/05/14/nginx-fcgi.html</link>
		<comments>http://blog.helosa.org/2010/05/14/nginx-fcgi.html#comments</comments>
		<pubDate>Fri, 14 May 2010 06:41:51 +0000</pubDate>
		<dc:creator>Chan Cham Chung</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.helosa.org/?p=256</guid>
		<description><![CDATA[我的想法是。。。快点，快点，再快点！！ apt-get install spawn-fcgi php5-cgi 用 spawn-fcgi 启动 fcgi ， spawn-fcgi -a 127.0.0.1 -p 8000 -u nobody -f /usr/bin/php-cgi -C 5 ; 在 nginx 里配置加一句： location ~ \.php$ { fastcgi_pass 127.0.0.1:8000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/nginx/html$fastcgi_script_name; include fastcgi_params; } 然后把一个 php 放在 /home/nginx/html 里，就可以使用了。]]></description>
			<content:encoded><![CDATA[<p>我的想法是。。。快点，快点，再快点！！</p>
<p>apt-get install spawn-fcgi php5-cgi</p>
<p>用 spawn-fcgi 启动 fcgi ，</p>
<p>spawn-fcgi -a 127.0.0.1 -p 8000 -u nobody -f /usr/bin/php-cgi -C 5 ;</p>
<p>在 nginx 里配置加一句：<br />
location ~ \.php$ {<br />
fastcgi_pass   127.0.0.1:8000;<br />
fastcgi_index  index.php;<br />
fastcgi_param  SCRIPT_FILENAME  /home/nginx/html$fastcgi_script_name;<br />
include        fastcgi_params;<br />
}</p>
<p>然后把一个 php 放在 /home/nginx/html 里，就可以使用了。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.helosa.org/2010/05/14/nginx-fcgi.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx 实现缓和切换新旧首页</title>
		<link>http://blog.helosa.org/2010/05/13/nginx-index.html</link>
		<comments>http://blog.helosa.org/2010/05/13/nginx-index.html#comments</comments>
		<pubDate>Thu, 13 May 2010 05:49:36 +0000</pubDate>
		<dc:creator>Chan Cham Chung</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://blog.helosa.org/?p=253</guid>
		<description><![CDATA[最近首页要改版，瞎折腾，还要新首页和旧首页并行服务，只有网友点击了“新版首页”的按钮后，才会显示新版首页，否则，显示旧版首页。 灵感来自 ayou 的一段配置，我的实现原理如下： 网友点击了切换按钮以后，利用 javascript set 一个 cookie ，如 newindex=y ，首页的 / 会作判断cookie ，然后 rewrite 到相应的页面。 具体实现： 1, 网友点击 set cookie，我抄了一段最简单的东西： &#60;html&#62; &#60;head&#62; &#60;title&#62;Welcome &#60;/title&#62; &#60;script type=&#8221;text/javascript&#8221;&#62; function Set_Cookie( name, value, expires, path, domain, secure ) { // set time, it&#8217;s in milliseconds var today = new Date(); today.setTime( today.getTime() ); /* if the [...]]]></description>
			<content:encoded><![CDATA[<p>最近首页要改版，瞎折腾，还要新首页和旧首页并行服务，只有网友点击了“新版首页”的按钮后，才会显示新版首页，否则，显示旧版首页。<br />
灵感来自 ayou 的一段配置，我的实现原理如下：</p>
<p>网友点击了切换按钮以后，利用 javascript set 一个  cookie ，如 newindex=y ，首页的 / 会作判断cookie ，然后 rewrite 到相应的页面。</p>
<p>具体实现：<br />
1,  网友点击 set cookie，我抄了一段最简单的东西：</p>
<div id="_mcePaste">&lt;html&gt;</div>
<div id="_mcePaste">&lt;head&gt;</div>
<div id="_mcePaste">&lt;title&gt;Welcome &lt;/title&gt;</div>
<div id="_mcePaste">&lt;script type=&#8221;text/javascript&#8221;&gt;</div>
<div id="_mcePaste">function Set_Cookie( name, value, expires, path, domain, secure )</div>
<div id="_mcePaste">{</div>
<div id="_mcePaste">// set time, it&#8217;s in milliseconds</div>
<div id="_mcePaste">var today = new Date();</div>
<div id="_mcePaste">today.setTime( today.getTime() );</div>
<div id="_mcePaste">/*</div>
<div id="_mcePaste">if the expires variable is set, make the correct</div>
<div id="_mcePaste">expires time, the current script below will set</div>
<div id="_mcePaste">it for x number of days, to make it for hours,</div>
<div id="_mcePaste">delete * 24, for minutes, delete * 60 * 24</div>
<div id="_mcePaste">*/</div>
<div id="_mcePaste">if ( expires )</div>
<div id="_mcePaste">{</div>
<div id="_mcePaste">expires = expires * 1000 * 60 * 60 * 24;</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">var expires_date = new Date( today.getTime() + (expires) );</div>
<div id="_mcePaste">document.cookie = name + &#8220;=&#8221; +escape( value ) +</div>
<div id="_mcePaste">( ( expires ) ? &#8220;;expires=&#8221; + expires_date.toGMTString() : &#8220;&#8221; ) +</div>
<div id="_mcePaste">( ( path ) ? &#8220;;path=&#8221; + path : &#8220;&#8221; ) +</div>
<div id="_mcePaste">( ( domain ) ? &#8220;;domain=&#8221; + domain : &#8220;&#8221; ) +</div>
<div id="_mcePaste">( ( secure ) ? &#8220;;secure&#8221; : &#8220;&#8221; );</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">&lt;/script&gt;</div>
<div id="_mcePaste">&lt;/head&gt;</div>
<div id="_mcePaste">&lt;body bgcolor=&#8221;white&#8221; text=&#8221;black&#8221;&gt;</div>
<div id="_mcePaste">&lt;center&gt;&lt;h1&gt;it is a test&lt;/h1&gt;&lt;/center&gt;</div>
<div id="_mcePaste">&lt;a href=&#8221;#&#8221; target=&#8221;_blank&#8221; onclick=&#8221;Set_Cookie( &#8216;newindex&#8217;, &#8216;y&#8217;, 30, &#8216;/&#8217;, &#8221;, &#8221; );window.location.href=&#8217;http://www.helosa.org/&#8217;;&#8221;&gt;我要访问新首页&lt;/a&gt;</div>
<div id="_mcePaste">&lt;/body&gt;</div>
<div id="_mcePaste">&lt;/html&gt;</div>
<p>2，nginx 配置：</p>
<p>location =/ {</p>
<p>root html ;<br />
index index.html ;<br />
if ( $cookie_newindex = &#8220;y&#8221; )<br />
{<br />
rewrite ^/*$ /index_new.html break;<br />
}</p>
<p>}</p>
<p>其中  /index.html 是旧首页，/index_new.html 是新首页。<br />
如此一来，网友访问 <a href="http://www.helosa.org/" target="_blank">http://www.helosa.org/</a> 时，  location / 就会根据cookie rewrite 到相应的首页。但是要注意的是，<br />
<a href="http://www.helosa.org/index.html" target="_blank">http://www.helosa.org/index.html</a><br />
<a href="http://www.helosa.org/index_new.html" target="_blank">http://www.helosa.org/index_new.html</a><br />
访问的是正确的页面，因为判断 cookie 只在 / 做。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.helosa.org/2010/05/13/nginx-index.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

