<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[阿权的书房]]></title> 
<link>http://www.aslibra.com/blog/index.php</link> 
<description><![CDATA[技术经验分享，资料收集，偶尔晾几张相片，感言生活]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[阿权的书房]]></copyright>
<item>
<link>http://www.aslibra.com/blog/post/lighttpd_upload-dirs.php</link>
<title><![CDATA[注意lighttpd的上传目录]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[lighttpd]]></category>
<pubDate>Mon, 07 Jun 2010 02:30:55 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/post/lighttpd_upload-dirs.php</guid> 
<description>
<![CDATA[ 
	今天某个服务器根分区已经满了，导致很多服务出错。<br/><br/>究其原因，是 /var/tmp 目录写满了文件：<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">lighttpd-upload-eIZa83&nbsp;&nbsp;lighttpd-upload-JwV3xq&nbsp;&nbsp;lighttpd-upload-P44hE4&nbsp;&nbsp;lighttpd-upload-Uinkoj&nbsp;&nbsp;lighttpd-upload-Zs2kwX<br/>lighttpd-upload-eJ03lT&nbsp;&nbsp;lighttpd-upload-JWvG2m&nbsp;&nbsp;lighttpd-upload-p4dNCH&nbsp;&nbsp;lighttpd-upload-uIpAlx&nbsp;&nbsp;lighttpd-upload-Zs3OTO<br/>lighttpd-upload-eJ0Soy&nbsp;&nbsp;lighttpd-upload-JwxFM6&nbsp;&nbsp;lighttpd-upload-p4Fpth&nbsp;&nbsp;lighttpd-upload-uiq7qV&nbsp;&nbsp;lighttpd-upload-ZS9G7z<br/>lighttpd-upload-Ej1kY9&nbsp;&nbsp;lighttpd-upload-Jx3QIZ&nbsp;&nbsp;lighttpd-upload-P4ghIw&nbsp;&nbsp;lighttpd-upload-uiQ8r6&nbsp;&nbsp;lighttpd-upload-ZSa7yh</div></div><br/>容易从文件名称看出来跟lighttpd有关<br/>检查lighttpd的配置得知，默认的上传路径是 /var/tmp<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">Description<br/>server.upload-dirs option<br/>defaults to /var/tmp as we assume it is a local harddisk <br/><br/>server.upload-dirs = ( "/var/tmp" )</div></div><br/>那相应的解决办法就是自己指定一个空间足够的目录了，比如：<br/><br/><div class="code">server.upload-dirs = (&quot;/Cache/aslibra.com/lighttpd-upload&quot;)</div><br/>注意是数组的形式，那估计可以设定多个目录<br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/lighttpd/" rel="tag">lighttpd</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/post/lighttpd_fastcgi_status.php</link>
<title><![CDATA[用lighttpd监测fastcgi的压力]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[lighttpd]]></category>
<pubDate>Fri, 26 Mar 2010 06:04:39 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/post/lighttpd_fastcgi_status.php</guid> 
<description>
<![CDATA[ 
	我个人喜欢用lighttpd作为php的web服务器，其中最欣赏的是信息统计。在这点上，apache和nginx还真的比不上，作为后端服务器，我比较推荐你使用，配置也简单。<br/><br/>安装和配置就不多说，网上另外可以找到。<br/>我们看看lighttpd里面的一些监测设置：<br/><br/><div class="code">status.status-url&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= &quot;/aslibra-status&quot;<br/>status.config-url&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= &quot;/aslibra-config&quot;<br/>status.statistics-url&nbsp;&nbsp;= &quot;/aslibra-counters&quot;</div><br/>第一个（status.status-url）是当前服务器的状态，一般情况下，你可以很清楚的知道现在在处理的是什么地址，也明白什么请求一直在处理并且处理了多少时间。很多时候你可以容易发现一些不容易看到的问题，毕竟处理时间久的请求肯定因为出问题了。<br/>第二个（status.config-url）是服务器的配置，比如：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">lighttpd 1.4.20<br/>Server-Features <br/>RegEx Conditionals enabled <br/>Network Engine <br/>fd-Event-Handler linux-sysepoll <br/>Config-File-Settings <br/>Loaded Modules indexfile<br/>rewrite<br/>redirect<br/>alias<br/>access<br/>status<br/>fastcgi<br/>proxy<br/>expire<br/>accesslog<br/>dirlisting<br/>staticfile </div></div><br/>你可以知道现在加载的有什么模块，可以在配置里增添。<br/>第三个（status.statistics-url）是今天要介绍的，它可以很清楚的知道php的压力分布，在mod_cache版本还可以知道缓存的命中率以及缓存的个数。<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">fastcgi.active-requests: 0<br/>fastcgi.backend.0.0.connected: 1145<br/>fastcgi.backend.0.0.died: 0<br/>fastcgi.backend.0.0.disabled: 0<br/>fastcgi.backend.0.0.load: 0<br/>fastcgi.backend.0.0.overloaded: 0<br/>fastcgi.backend.0.load: 1<br/>fastcgi.requests: 1145</div></div><br/>你可以从上述信息了解到，当前php处理过1145个请求，压力很小，没有正在处理的php请求。<br/><br/>配置文件里，你可以自定义fastcgi服务器的名称来区分不同的请求，比如：<br/><br/><div class="code">#默认的<br/>fastcgi.server = ( &quot;.php&quot; =&gt;(<br/>&nbsp;&nbsp;&nbsp;&nbsp;( &quot;host&quot; =&gt; &quot;127.0.0.1&quot;,&quot;port&quot; =&gt; 9000,)<br/>&nbsp;&nbsp;)<br/>)<br/><br/>$HTTP&#91;&quot;host&quot;&#93; == &quot;www.aslibra.com&quot; &#123;<br/>&nbsp;&nbsp;server.document-root = &quot;/Data/webapps/www.aslibra.com&quot;<br/>&nbsp;&nbsp;fastcgi.server = ( &quot;.php&quot; =&gt;(<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;www&quot;=&gt;( &quot;host&quot; =&gt; &quot;127.0.0.1&quot;,&quot;port&quot; =&gt; 9000,)<br/>&nbsp;&nbsp;&nbsp;&nbsp;)<br/>&nbsp;&nbsp;)<br/>&#125;<br/><br/>$HTTP&#91;&quot;host&quot;&#93; == &quot;dl.aslibra.com&quot; &#123;<br/>&nbsp;&nbsp;server.document-root = &quot;/Data/webapps/dl.aslibra.com&quot;<br/>&nbsp;&nbsp;fastcgi.server = ( &quot;.php&quot; =&gt;(<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;dl&quot;=&gt;( &quot;host&quot; =&gt; &quot;127.0.0.1&quot;,&quot;port&quot; =&gt; 9000,)<br/>&nbsp;&nbsp;&nbsp;&nbsp;)<br/>&nbsp;&nbsp;)<br/>&#125;</div><br/>你可以看到如下的统计信息：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">fastcgi.active-requests: 3<br/>fastcgi.backend.0.0.connected: 4775<br/>fastcgi.backend.0.0.died: 0<br/>fastcgi.backend.0.0.disabled: 0<br/>fastcgi.backend.0.0.load: 0<br/>fastcgi.backend.0.0.overloaded: 0<br/>fastcgi.backend.0.load: 0<br/>fastcgi.backend.dl.0.connected: 863<br/>fastcgi.backend.dl.0.died: 0<br/>fastcgi.backend.dl.0.disabled: 0<br/>fastcgi.backend.dl.0.load: 0<br/>fastcgi.backend.dl.0.overloaded: 0<br/>fastcgi.backend.dl.load: 0<br/>fastcgi.backend.www.0.connected: 696191<br/>fastcgi.backend.www.0.died: 0<br/>fastcgi.backend.www.0.disabled: 0<br/>fastcgi.backend.www.0.load: 3<br/>fastcgi.backend.www.0.overloaded: 0<br/>fastcgi.backend.www.load: 3<br/>fastcgi.requests: 701829</div></div><br/><strong>说明什么问题呢？</strong><br/><br/>1 压力主要来自www，dl的站点php的处理压力很小<br/>2 www的并发处理有3个，也许这个数字比较高时，你可以看看status.status-url里到底有哪些地址正在处理<br/>3 都还没有发生php请求死掉(died)的情况，还是良好的<br/><br/>有了这些统计信息，有助于你避免一些问题的发生，总比蒙着眼睛用nginx和apache好。<br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/lighttpd/" rel="tag">lighttpd</a> , <a href="http://www.aslibra.com/blog/go.php/tags/php/" rel="tag">php</a> , <a href="http://www.aslibra.com/blog/go.php/tags/fastcgi/" rel="tag">fastcgi</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/post/lighttpd_rewrite_url.php</link>
<title><![CDATA[lighttpd重写地址到非网站目录]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[lighttpd]]></category>
<pubDate>Fri, 20 Nov 2009 02:00:20 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/post/lighttpd_rewrite_url.php</guid> 
<description>
<![CDATA[ 
	lighttpd可以rewrite地址到一个php文件处理所有相关的请求，比如：<br/><div class="code">url.rewrite-once = (<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;^/c/&quot; =&gt; &quot;/page_c.php&quot;<br/>)</div><br/>这个/是从网站根目录开始算的，所以不能指定其它目录的文件<br/>需要制定其它目录的文件，那可以先alias处理，比如<br/><br/><div class="code">$HTTP&#91;&quot;host&quot;&#93; == &quot;www.aslibra.com&quot; &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server.document-root = &quot;/Data/webapps/www.aslibra.com&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alias.url = (<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;/page_c.php&quot; =&gt; &quot;/Data/webapps/test.aslibra.com/page_c.php&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url.rewrite-once = (<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;^/c/&quot; =&gt; &quot;/page_c.php&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)<br/>&#125;</div><br/><br/>先定义一个本地文件为文件系统的另外一个文件<br/>然后rewrite到此文件即可！<br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/lighttpd/" rel="tag">lighttpd</a> , <a href="http://www.aslibra.com/blog/go.php/tags/rewrite/" rel="tag">rewrite</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/post/lighttpd_cache_rewrite_fix_directory_erro.php</link>
<title><![CDATA[lighttpd的缓存注意地址形式]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[lighttpd]]></category>
<pubDate>Thu, 21 May 2009 14:17:55 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/post/lighttpd_cache_rewrite_fix_directory_erro.php</guid> 
<description>
<![CDATA[ 
	今日发现lighttpd的日志有大量的错误是同样的错误提示：<br/><br/><div class="code">2009-05-21 18:39:06: (mod_cache.c.2080) failed to delete old cache file /cache/web/www.aslibra.com/search/article/11433 before update Is a directory</div><br/><br/>因为存在11433/1 的下级目录，而lighttpd根据地址认为 11433 是一个文件，删除的时候出错了，代码位置是：<br/><br/><div class="code">&nbsp;&nbsp; if (unlink(file-&gt;ptr) &amp;&amp; errno != ENOENT) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;log_error_write(srv, __FILE__, __LINE__, &quot;sbss&quot;, &quot;failed to delete old cache file&quot;, <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hctx-&gt;file, &quot;before update&quot;, strerror(errno));</div><br/><br/>unlink只能删除文件，不能删除文件夹，所以删除失败。<br/>在linux下同一个目录下不会有同名的文件和文件夹<br/><br/><div class="code">&#91;root@localhost test&#93;# ll<br/>total 8<br/>-rw-r--r--&nbsp;&nbsp;1 root root 1 May 24 02:08 a<br/>&#91;root@localhost test&#93;# mkdir a<br/>mkdir: `a&#039; exists but is not a directory<br/>&#91;root@localhost test&#93;# mkdir b<br/>&#91;root@localhost test&#93;# ll<br/>total 16<br/>-rw-r--r--&nbsp;&nbsp;1 root root&nbsp;&nbsp;&nbsp;&nbsp;1 May 24 02:08 a<br/>drwxr-xr-x&nbsp;&nbsp;2 root root 4096 May 24 02:16 b<br/>&#91;root@localhost test&#93;# echo&gt;b<br/>-bash: b: Is a directory</div><br/><br/>也就是说，如果 /a/1 的地址先访问，/a/1 的文件就先创建了<br/>如果 /a/1/index.htm 先访问，/a/1 的文件夹先创建，老外一种形式就无法再缓存，这个就给后端带来了压力。<br/><br/>这个可以用redirect或者rewrite修正，参考做法：<br/><br/><div class="code">$HTTP&#91;&quot;host&quot;&#93; == &quot;www.aslibra.com&quot; &#123;<br/>&nbsp;&nbsp;#指定规则补全地址<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url.redirect = (<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;^/search/(article&#124;pic)/(&#91;^/&#93;+)$&quot; =&gt; &quot;/search/$1/$2/&quot;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$HTTP&#91;&quot;url&quot;&#93; =~ &quot;^/search/&quot; &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;#可以重新制定目录缓存文件，避免原先的文件冲突<br/>&nbsp;&nbsp;&nbsp;&nbsp;cache.bases = (&quot;/cache/web/search/&quot;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cache.support-queries = &quot;disable&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy.server&nbsp;&nbsp;= ( &quot;&quot; =&gt;(<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;( &quot;host&quot; =&gt; &quot;192.168.1.2&quot;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;))<br/>&#125;</div><br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/lighttpd/" rel="tag">lighttpd</a> , <a href="http://www.aslibra.com/blog/go.php/tags/cache/" rel="tag">cache</a> , <a href="http://www.aslibra.com/blog/go.php/tags/rewrite/" rel="tag">rewrite</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/post/quehy_lighttpd_modcache.php</link>
<title><![CDATA[八卦一下quehy]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[lighttpd]]></category>
<pubDate>Sat, 16 May 2009 03:34:29 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/post/quehy_lighttpd_modcache.php</guid> 
<description>
<![CDATA[ 
	一直使用lighttpd的modcache，作者博客是：<br/><br/><a href="http://blog.quehy.com/" target="_blank">http://blog.quehy.com/</a><br/><br/>我一直不理解quehy是什么意思，query的变异？还是英文名？今天无意中看到人物介绍才理解意思:<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">不知道你有没有印象，之前我介绍的magent就出自该牛人，顺便八卦一下，google了一下，果然强<br/><br/>“阙宏宇是一名传奇人物。阙宏宇却连跳数级，15岁便一举考中清华大学自动系，19岁被保送到中国科学院计算机系攻读硕士研究生。毕业后历任Chinaren校友录的技术总监和sohu无线事业部总监，sohu网站的闪电邮系统和chinaren的校友录架构都是以他为主开发的。”</div></div><br/><br/>出自：<a href="http://www.sysbus.com/?p=184" target="_blank">http://www.sysbus.com/?p=184</a><br/><br/>从名字我就知道域名的意思了，原来是强人一个，我也很希望以后能做点开源项目。<br/><br/>他启动的两个开源项目我都非常喜欢：<br/>1 <a href="http://www.linux.com.cn/modcache/" target="_blank">lighttpd的modcache</a><br/>我一直在使用，已经代替了squid的位置，使用效果还是不错的<br/>2 <a href="http://code.google.com/p/memagent/" target="_blank">memagent</a><br/>这个也很实用，一直也在考虑加强memcached的稳定性的问题，看来这又给我带来了解决方案<br/><br/><br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/lighttpd/" rel="tag">lighttpd</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/post/lighttpd_mod_cache_php_content_length.php</link>
<title><![CDATA[lighttpd的mod_cache缓存不了的问题]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[lighttpd]]></category>
<pubDate>Wed, 22 Apr 2009 14:24:27 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/post/lighttpd_mod_cache_php_content_length.php</guid> 
<description>
<![CDATA[ 
	lighttpd的cache功能一直使用的都比较不错：<br/><br/>1 配置简洁<br/>2 cpu和内存占用不算多，性能良好<br/><br/><strong>但也是有缺点的地方：</strong><br/><br/>1 文件缓存数量巨大时在不断蚕食内存，最好有大内存的服务器做这事，当然了，缓存项目多了自然占用内存多<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">cache.cached-itmes: 707831<br/>cache.hitrate(%): 18<br/>cache.memory-inuse(KB): 44239<br/>#这个状态会占用了500多M内存</div></div><br/><br/>2 文件体系的缓存模式，不知道是否在文件夹文件过多的时候效率不好呢，猜的<br/>3 不知道是否协议上的小问题，导致部分缓存不成功<br/>4 单进程重启有中断<br/><br/>今天是讨论这第三点，在日志里可以找到症状：<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">2009-04-22 19:18:26: (mod_cache.c.1336) ignore no content-length and no chunked transfer-encoding uri / <br/>2009-04-22 19:18:37: (mod_cache.c.1336) ignore no content-length and no chunked transfer-encoding uri /article/4559/ <br/>2009-04-22 19:18:44: (mod_cache.c.1336) ignore no content-length and no chunked transfer-encoding uri /article/4559/ <br/>2009-04-22 19:19:01: (mod_cache.c.1336) ignore no content-length and no chunked transfer-encoding uri /article/4559/ <br/>2009-04-22 19:19:09: (mod_cache.c.1336) ignore no content-length and no chunked transfer-encoding uri /aslibra/com/ <br/>2009-04-22 19:19:24: (mod_cache.c.1336) ignore no content-length and no chunked transfer-encoding uri /aslibra/com/ <br/></div></div><br/><br/>某些PHP处理的请求一直都缓存不上，幸好后端服务器加了缓存控制，否则会疯了的。<br/><br/><strong>我们可以看看mod_cache.c的部分代码：</strong><br/><br/><div class="code">###井号开始的是我理解的内容<br/>static int check_response_iscachable(server *srv, connection *con, plugin_data *p, handler_ctx *hctx)<br/>....<br/>#只缓存200的响应<br/>if (con-&gt;http_status != 200) return 0;<br/>....<br/>#似乎有缓存gzip和deflate的可能<br/>if (p-&gt;conf.support_accept_encoding == 0 ) &#123;<br/>&nbsp;&nbsp;if (p-&gt;conf.debug) <br/>&nbsp;&nbsp;&nbsp;&nbsp;log_error_write(srv, __FILE__, __LINE__, &quot;sb&quot;, &quot;ignore response uri with CE&quot;, con-&gt;uri.path);<br/>&nbsp;&nbsp;return 0;<br/>&#125; else &#123;<br/>&nbsp;&nbsp;if (strcasecmp(ds-&gt;value-&gt;ptr, &quot;gzip&quot;) == 0) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;hctx-&gt;content_encoding_type = 1;<br/>&nbsp;&nbsp;&#125; else if (strcasecmp(ds-&gt;value-&gt;ptr, &quot;deflate&quot;) == 0) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;hctx-&gt;content_encoding_type = 2;<br/>&nbsp;&nbsp;&#125; <br/>&#125;<br/>....<br/>#不缓存带Set-Cookie的信息<br/>if (NULL != (ds = (data_string *)array_get_element(con-&gt;response.headers, &quot;Set-Cookie&quot;))) &#123;<br/>....<br/>#一些cache-control的判断<br/>NULL != (ds = (data_string *)array_get_element(con-&gt;response.headers, &quot;Cache-Control&quot;)) &amp;&amp;<br/>....<br/>#不缓存比当前时间早的，记得调整服务器时间，否则这里会出问题<br/>(NULL != (ds = (data_string *)array_get_element(con-&gt;response.headers, &quot;Expires&quot;)))<br/>....<br/>#检查是否有content_length或者chunked标识<br/>if ((p-&gt;conf.dynamic_mode == 0) &amp;&amp; (con-&gt;response.content_length &lt; 0) &amp;&amp; <br/>&nbsp;&nbsp;!(con-&gt;response.transfer_encoding &amp; HTTP_TRANSFER_ENCODING_CHUNKED)) &#123;<br/>&nbsp;&nbsp;log_error_write(srv, __FILE__, __LINE__, &quot;sb&quot;, &quot;ignore no content-length and no chunked transfer-encoding uri&quot;, con-&gt;uri.path);<br/>&nbsp;&nbsp;return 0;<br/>&#125;<br/>....<br/></div><br/><br/>看源代码就是能够理解什么样的响应lighttpd才会缓存了。<br/>一直不太相信最后一个检查居然过不了，日志里面都是这样的提示，因为在直接访问源服务器都是正常的，比如：<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">(Status-Line)&nbsp;&nbsp;HTTP/1.0 200 OK<br/>Cache-Control&nbsp;&nbsp;max-age=1800<br/>Connection&nbsp;&nbsp;keep-alive<br/>Content-Length&nbsp;&nbsp;30900<br/>Content-type&nbsp;&nbsp;text/html<br/>Date&nbsp;&nbsp;Wed, 22 Apr 2009 13:42:56 GMT<br/>Expires&nbsp;&nbsp;Wed, 22 Apr 2009 13:57:56 GMT<br/>Server&nbsp;&nbsp;lighttpd/1.4.19<br/>X-Powered-By&nbsp;&nbsp;PHP/5.2.6</div></div><br/><br/>但是在命令行用curl请求时就不一样了：<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">[root@localhost log]# curl -I http://123.45.6.7/article/4559/ -H "host:www.aslibra.com"<br/>HTTP/1.1 200 OK<br/>Expires: Wed, 22 Apr 2009 12:26:20 GMT<br/>Cache-Control: max-age=1800<br/>X-Powered-By: PHP/5.2.6<br/>Content-type: text/html<br/>Date: Wed, 22 Apr 2009 12:11:20 GMT<br/>Server: lighttpd/1.4.19</div></div><br/><br/>curl的命令是否类似于lighttpd对源服务器proxy请求的呢？<br/>如果是，那就还是在PHP里面处理一下吧：<br/><br/><div class="code">&lt;?<br/>ob_start();<br/><br/>//your code...<br/><br/>$html = ob_get_contents();<br/>//输出文件长度信息<br/>@header(&#039;Content-Length:&#039;.strlen($html));<br/>?&gt;</div><br/><br/>可以得到正常的信息：<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">[root@localhost log]# curl -I http://123.45.6.7/article/4559/ -H "host:www.aslibra.com"<br/>HTTP/1.0 200 OK<br/>Connection: close<br/>Expires: Wed, 22 Apr 2009 14:22:24 GMT<br/>Cache-Control: max-age=1800<br/>X-Powered-By: PHP/5.2.6<br/>Content-Length: 28377<br/>Content-type: text/html<br/>Date: Wed, 22 Apr 2009 14:07:24 GMT<br/>Server: lighttpd/1.4.19</div></div><br/><br/>cache服务器响应：<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">(Status-Line)&nbsp;&nbsp;HTTP/1.1 200 OK<br/>Accept-Ranges&nbsp;&nbsp;bytes<br/>Cache-Control&nbsp;&nbsp;max-age=290<br/>Content-Encoding&nbsp;&nbsp;gzip<br/>Content-Length&nbsp;&nbsp;8366<br/>Content-Type&nbsp;&nbsp;text/html<br/>Date&nbsp;&nbsp;Wed, 22 Apr 2009 14:15:39 GMT<br/>ETag&nbsp;&nbsp;"-845823938"<br/>Expires&nbsp;&nbsp;Wed, 22 Apr 2009 14:17:32 GMT<br/>Last-Modified&nbsp;&nbsp;Wed, 22 Apr 2009 14:12:32 GMT<br/>Server&nbsp;&nbsp;lighttpd/1.4.19<br/>Vary&nbsp;&nbsp;Accept-Encoding<br/>X-Cache&nbsp;&nbsp;HIT<br/>X-Powered-By&nbsp;&nbsp;PHP/5.2.6</div></div><br/><br/>这样应该可以解决此类问题，大家使用愉快。<br/><br/><strong>附录：</strong><br/><br/>lighttpd的cache模块配置：<a href="http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModCache" target="_blank">Web Accelerating Cache</a><br/>官网：<a href="http://www.linux.com.cn/modcache/" target="_blank">http://www.linux.com.cn/modcache/</a><br/>作者博客：<a href="http://blog.quehy.com/" target="_blank">http://blog.quehy.com/</a><br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/php/" rel="tag">php</a> , <a href="http://www.aslibra.com/blog/go.php/tags/lighttpd/" rel="tag">lighttpd</a> , <a href="http://www.aslibra.com/blog/go.php/tags/cache/" rel="tag">cache</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/read.php/1158.htm</link>
<title><![CDATA[lighttpd+php fast-cgi更加轻快]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[lighttpd]]></category>
<pubDate>Thu, 06 Nov 2008 16:30:23 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/read.php/1158.htm</guid> 
<description>
<![CDATA[ 
	<a href="http://pic.yupoo.com/hqlulu/2788667689e2/4ze1v8qy.jpg" target="_blank"><img src="http://pic.yupoo.com/hqlulu/2788667689e2/4ze1v8qy.jpg" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>图：更换lighttpd+php fast-cgi的变化<br/><br/>原先服务器是apache的，加载php5模块，还有mysql运行，但一直负载很高，把mysql用到局域网的另外一个机器，占用CPU更加高，快疯了。可能apache进程太多，每个进程都吃太多内存了？具体原因不知道。<br/><br/>昨天晚上把php-fastcgi安装好了，打包文件见新浪的资料共享：<br/><a href="http://ishare.iask.sina.com.cn/cgi-bin/fileid.cgi?fileid=4537134" target="_blank">http://ishare.iask.sina.com.cn/cgi-bin/fileid.cgi?fileid=4537134</a><br/><br/>安装好后，把apache的日志对应lighttpd写好，转换好之前的配置，然后发现一个问题，rewrite后的url已经是变化了的，大家要注意（示例说明）：<br/><br/><br/><div class="code">$HTTP&#91;&quot;host&quot;&#93; == &quot;test.aslibra.com&quot; &#123;<br/>&nbsp;&nbsp;url.rewrite-once = (<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;^/s&quot; =&gt; &quot;/__s.php&quot;,<br/>&nbsp;&nbsp;)<br/>&nbsp;&nbsp;server.document-root = &quot;/Data/webapps/test.aslibra.com&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$HTTP&#91;&quot;url&quot;&#93; =~ &quot;^&#92;/__s&quot; &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;accesslog.filename = &quot;&#124;/Data/apps/cronolog/sbin/cronolog /log/%Y/%m/%d/sub.%m%d%H&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&#125;</div><br/><br/>启动后，负载变轻了好多好多，流量还正常。<br/>看来php的fast-cgi应该好好配置好，apache的确有点重了。。<br/>不过今天有发现假死情况，重启也无法启动lighttpd，不知道是否php-cgi占用内存多了还是啥，有待观察。。。<br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/lighttpd/" rel="tag">lighttpd</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/read.php/1147.htm</link>
<title><![CDATA[注意lighttpd的compress目录增长]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[lighttpd]]></category>
<pubDate>Thu, 16 Oct 2008 05:45:18 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/read.php/1147.htm</guid> 
<description>
<![CDATA[ 
	今天发现上传不了图片了，还以为是程序出问题了。<br/><br/>PHP上传文件是类似的错误<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">Array(<br/>&nbsp;&nbsp;&nbsp;&nbsp;[name] => 1711.jpg<br/>&nbsp;&nbsp;&nbsp;&nbsp;[type] => <br/>&nbsp;&nbsp;&nbsp;&nbsp;[tmp_name] => <br/>&nbsp;&nbsp;&nbsp;&nbsp;[error] => 6<br/>&nbsp;&nbsp;&nbsp;&nbsp;[size] => 0<br/>)</div></div><br/><br/>检查磁盘，网站目录都还正常，还有200G空间呢，不可能出现这样的问题。就发现根目录已经使用了百分之九十多了，具体数值忘记了，可能是系统保护的预留的空间。<br/><br/>重启了一下lighttpd，发现有如下提示：<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">2008-10-16 11:50:49: (mod_compress.c.415) couldn't create directory for file /tmp/lighttpd/cache/compress/12798222/index.htm-gzip-64391395-13510-1215020773 <br/><br/>[root@localhost lighttpd]# xc_fcntl_create: open(/tmp/.xcache.2.0.1804289383.lock, O_RDWR&#124;O_CREAT, 0666) failed:PHP Fatal error:&nbsp;&nbsp;XCache: can't create lock in Unknown on line 0<br/>PHP Fatal error:&nbsp;&nbsp;XCache: failed init opcode cache in Unknown on line 0<br/><br/>[root@localhost lighttpd]# 2008-10-16 11:53:50: (mod_fastcgi.c.1743) connect failed: No such file or directory on unix:/tmp/php.socket-3 </div></div><br/><br/>第一个是lighttpd的compress的模块，是写入文件的<br/>第二个是XCache的临时目录写入<br/>第三个是php的socket文件<br/><br/>看来是tmp目录所在的分区满了。<br/>大体应该是lighttpd使用的压缩文件占用空间越来越大，导致空间不足，把lighttpd的compress目录重新设置到富裕的分区就好，然后把tmp目录的压缩文件目录都删掉即可。<br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/lighttpd/" rel="tag">lighttpd</a> , <a href="http://www.aslibra.com/blog/go.php/tags/linux/" rel="tag">linux</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/read.php/1109.htm</link>
<title><![CDATA[lighttpd可以引用的HTTP[]数据]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[lighttpd]]></category>
<pubDate>Tue, 19 Aug 2008 05:56:57 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/read.php/1109.htm</guid> 
<description>
<![CDATA[ 
	lighttpd做判断的时候可以很灵活，比如：<br/><br/><div class="code">$HTTP&#91;&quot;host&quot;&#93; == &quot;www.example.org&quot; &#123;<br/>&nbsp;&nbsp;$HTTP&#91;&quot;remoteip&quot;&#93; != &quot;10.0.0.0/8&quot; &#123;<br/>&nbsp;&nbsp; url.access-deny = ( &quot;&quot; )<br/>&nbsp;&nbsp;&#125;<br/>&#125;</div><br/><br/>$HTTP数组里面有如下的变量可以引用（官方）：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">$HTTP[&quot;cookie&quot;] <br/>match on cookie <br/>$HTTP[&quot;host&quot;] <br/>match on host <br/>$HTTP[&quot;useragent&quot;] <br/>match on useragent <br/>$HTTP[&quot;referer&quot;] <br/>match on referer <br/>$HTTP[&quot;url&quot;] <br/>match on url. If there are nested blocks, this must be the most inner block. <br/>$HTTP[&quot;querystring&quot;] <br/>match on querystring, eg, after the ? in this type url: index.php?module=images.. <br/>$HTTP[&quot;remoteip&quot;] <br/>match on the remote IP or a remote Network (Warning: doesn&#039;t work with IPv6 enabled) <br/>$HTTP[&quot;scheme&quot;] (Introduced in version 1.4.19) <br/>match on the scheme used by the incoming connection. This is either &quot;http&quot; or &quot;https&quot;. <br/>$SERVER[&quot;socket&quot;] <br/>match on socket. Value must be on the format &quot;ip:port&quot; where ip is an IP address and port a port number, or &quot;:port&quot; to match port only. Only equal match (==) is supported. It also binds the daemon to this socket. Use this if you want to do IP/port-based virtual hosts. <br/>$PHYSICAL[&quot;path&quot;] (Introduced in version 1.5.0) <br/>match on the mapped physical path of the file / cgi script to be served. <br/>$PHYSICAL[&quot;existing-path&quot;] (Introduced in version 1.5.0) <br/>match on the mapped physical path of the file / cgi script to be served only if such a file exists on the local filesystem. </div></div><br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/lighttpd/" rel="tag">lighttpd</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/read.php/1085.htm</link>
<title><![CDATA[lighttpd的proxy设置不支持域名的方式]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[lighttpd]]></category>
<pubDate>Wed, 16 Jul 2008 14:25:00 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/read.php/1085.htm</guid> 
<description>
<![CDATA[ 
	<div class="code">$HTTP&#91;&quot;host&quot;&#93; == &quot;a.aslibra.com&quot; &#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp;proxy.server = ( &quot;&quot; =&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( (<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;host&quot; =&gt; &quot;b.aslibra.com&quot;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ) )<br/> &nbsp; &nbsp; &nbsp; &nbsp; )<br/>&#125;</div><br/><br/>这样的代码在apache里面是正常的，今天使用lighttpd就发现出现 500 的内部错误。<br/>于是查资料，看看lighttpd的官方说明：<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">&lt;extension&gt;: is the file-extension or prefix (if started with &quot;/&quot;) might empty to match all requests <br/>&quot;host&quot;: is ip of the proxy server &#039;&#039;DO not use hostnames here! only IP Addresses&#039;&#039; <br/>&quot;port&quot;: is tcp-port on the &quot;host&quot; used by the proxy server (default: 80) </div></div><br/><br/>也就是不允许用域名了，不知道是否正常，可以测试一下：<br/><br/>做个PHP文件：<br/><br/>proxy.php<br/><div class="code">&lt;?<br/>ob_start();<br/>print_r($_SERVER);<br/>$a=ob_get_contents();<br/>file_put_contents(&quot;log.txt&quot;,$a);<br/>?&gt;</div><br/><br/>得到代码：<br/>wget http://127.0.0.1/proxy.php<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"> &nbsp; &nbsp;[SERVER_NAME] =&gt; 127.0.0.1<br/> &nbsp; &nbsp;[GATEWAY_INTERFACE] =&gt; CGI/1.1<br/> &nbsp; &nbsp;[SERVER_PORT] =&gt; 80<br/> &nbsp; &nbsp;[SERVER_ADDR] =&gt; 127.0.0.1<br/> &nbsp; &nbsp;[REMOTE_PORT] =&gt; 50677<br/> &nbsp; &nbsp;[REMOTE_ADDR] =&gt; 127.0.0.1</div></div><br/><br/>指定proxy和hosts文件：<br/>127.0.0.1 proxy.aslibra.com<br/><br/><div class="code">$HTTP&#91;&quot;host&quot;&#93; == &quot;proxy.aslibra.com&quot; &#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp;proxy.server = ( &quot;&quot; =&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( (<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;host&quot; =&gt; &quot;127.0.0.1&quot;,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;port&quot; =&gt; 80<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ) )<br/> &nbsp; &nbsp; &nbsp; &nbsp; )<br/>&#125;</div><br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"> &nbsp; &nbsp;[SERVER_NAME] =&gt; proxy.aslibra.com<br/> &nbsp; &nbsp;[GATEWAY_INTERFACE] =&gt; CGI/1.1<br/> &nbsp; &nbsp;[SERVER_PORT] =&gt; 80<br/> &nbsp; &nbsp;[SERVER_ADDR] =&gt; 127.0.0.1<br/> &nbsp; &nbsp;[REMOTE_PORT] =&gt; 50676<br/> &nbsp; &nbsp;[REMOTE_ADDR] =&gt; 127.0.0.1</div></div><br/><br/>也就是发送的还是当前的主机域名，所以proxy也不用担心只是按IP访问，和正常的代理一样。<br/><br/>但是，这样的话，如果域名指向有变化，那这里就不方便了，apache里面可以用域名的方式，那其实可以不用担心域名指向变化，但lighttpd这样肯定对效率有很大的提高。<br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/lighttpd/" rel="tag">lighttpd</a> , <a href="http://www.aslibra.com/blog/go.php/tags/proxy/" rel="tag">proxy</a>
]]>
</description>
</item>
</channel>
</rss>