<?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>Elias的邪异门 &#187; Lighttpd</title>
	<atom:link href="http://blog.elias.cn/archives/tag/lighttpd/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.elias.cn</link>
	<description>倒苦水之家</description>
	<lastBuildDate>Tue, 25 Oct 2011 13:38:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>在Lighttpd上使用wp-super-cache</title>
		<link>http://blog.elias.cn/archives/328</link>
		<comments>http://blog.elias.cn/archives/328#comments</comments>
		<pubDate>Mon, 11 May 2009 09:51:39 +0000</pubDate>
		<dc:creator>Elias</dc:creator>
				<category><![CDATA[个人网站的工具与思考]]></category>
		<category><![CDATA[Lighttpd]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://blog.elias.cn/?p=328</guid>
		<description><![CDATA[wp-super-cache是WordPress的一个静态缓存插件，对访问量大的博客或是在系统中使用了性能较差的插件时都是挺有用的。但这个玩意需要Apache的mod_rewrite来支持，lighty下可没有这玩意儿。所以需要咱们自己添加一个lua脚本，配合lighty的mod_magnet模块来代替mod_rewrite的功能。整个操作步骤是这样的： lighty中博客站点的配置文件要这么写： ?View Code TEXT$HTTP[&#34;host&#34;] == &#34;blog.elias.cn&#34; { server.document-root = &#34;/home/public_html/elias&#34; magnet.attract-physical-path-to = ( server.document-root + &#34;/rewrite.lua&#34; ) } 这里能用magnet.attract-physical-path-to的前提是mod_magnet已经安装并启用了，否则在lighty的error.log会报错。Debian里mod_magnet是单独的一个包，叫做lighttpd-mod-magnet，安装以后就可以把mod_magnet加入lighty的配置文件了。 然后再在博客站点的根目录新建一个名为rewrite.lua的脚本文件，文件内容为： ?Download rewrite.lua1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 [...]]]></description>
			<content:encoded><![CDATA[<p>wp-super-cache是WordPress的一个静态缓存插件，对访问量大的博客或是在系统中使用了性能较差的插件时都是挺有用的。但这个玩意需要Apache的mod_rewrite来支持，lighty下可没有这玩意儿。所以需要咱们自己添加一个lua脚本，配合lighty的mod_magnet模块来代替mod_rewrite的功能。整个操作步骤是这样的：</p>

<p>lighty中博客站点的配置文件要这么写：</p>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p328code3'); return false;">View Code</a> TEXT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3283"><td class="code" id="p328code3"><pre class="text" style="font-family:monospace;">$HTTP[&quot;host&quot;] == &quot;blog.elias.cn&quot; {
  server.document-root = &quot;/home/public_html/elias&quot;
  magnet.attract-physical-path-to = ( server.document-root + &quot;/rewrite.lua&quot; )
}</pre></td></tr></table></div>


<p>这里能用magnet.attract-physical-path-to的前提是mod_magnet已经安装并启用了，否则在lighty的error.log会报错。Debian里mod_magnet是单独的一个包，叫做lighttpd-mod-magnet，安装以后就可以把mod_magnet加入lighty的配置文件了。</p>

<p>然后再在博客站点的根目录新建一个名为rewrite.lua的脚本文件，文件内容为：</p>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://blog.elias.cn/wp-content/plugins/wp-codebox/wp-codebox.php?p=328&amp;download=rewrite.lua">rewrite.lua</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3284"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code" id="p328code4"><pre class="lua" style="font-family:monospace;"><span style="color: #b1b100;">function</span> serve_html<span style="color: #66cc66;">&#40;</span>cached_page<span style="color: #66cc66;">&#41;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>lighty.stat<span style="color: #66cc66;">&#40;</span>cached_page<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
    lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> cached_page
    <span style="color: #b1b100;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Serving cached page: &quot;</span> .. cached_page<span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #b1b100;">true</span>
  <span style="color: #b1b100;">else</span>
    <span style="color: #b1b100;">return</span> <span style="color: #b1b100;">false</span>
  <span style="color: #b1b100;">end</span>
<span style="color: #b1b100;">end</span>
&nbsp;
<span style="color: #b1b100;">function</span> serve_gzip<span style="color: #66cc66;">&#40;</span>cached_page<span style="color: #66cc66;">&#41;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>lighty.stat<span style="color: #66cc66;">&#40;</span>cached_page .. <span style="color: #ff0000;">&quot;.gz&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
    lighty.header<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Content-Encoding&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;gzip&quot;</span>
    lighty.header<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;&quot;</span>
    lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> cached_page .. <span style="color: #ff0000;">&quot;.gz&quot;</span>
    <span style="color: #b1b100;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Serving gzipped page: &quot;</span> .. cached_page .. <span style="color: #ff0000;">&quot;.gz&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #b1b100;">true</span>
  <span style="color: #b1b100;">else</span>
    <span style="color: #b1b100;">return</span> <span style="color: #b1b100;">false</span>
  <span style="color: #b1b100;">end</span>
<span style="color: #b1b100;">end</span>
&nbsp;
attr <span style="color: #66cc66;">=</span> lighty.stat<span style="color: #66cc66;">&#40;</span>lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">and</span> lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span> ~<span style="color: #66cc66;">=</span> lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.doc-root&quot;</span><span style="color: #66cc66;">&#93;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> attr<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
  lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;uri.path&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;/index.php&quot;</span>
  lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.rel-path&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;uri.path&quot;</span><span style="color: #66cc66;">&#93;</span>
  lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.doc-root&quot;</span><span style="color: #66cc66;">&#93;</span> .. lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.rel-path&quot;</span><span style="color: #66cc66;">&#93;</span>
&nbsp;
  query_condition <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">not</span> <span style="color: #66cc66;">&#40;</span>lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;uri.query&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">and</span> <span style="color: #b1b100;">string.find</span><span style="color: #66cc66;">&#40;</span>lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;uri.query&quot;</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #ff0000;">&quot;.*s=.*&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  user_cookie <span style="color: #66cc66;">=</span> lighty.request<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Cookie&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">or</span> <span style="color: #ff0000;">&quot;no_cookie_here&quot;</span>
  cookie_condition <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">not</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string.find</span><span style="color: #66cc66;">&#40;</span>user_cookie, <span style="color: #ff0000;">&quot;.*comment_author.*&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #b1b100;">string.find</span><span style="color: #66cc66;">&#40;</span>user_cookie, <span style="color: #ff0000;">&quot;.*wordpress.*&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #b1b100;">string.find</span><span style="color: #66cc66;">&#40;</span>user_cookie, <span style="color: #ff0000;">&quot;.*wp-postpass_.*&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>query_condition <span style="color: #b1b100;">and</span> cookie_condition<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
    accept_encoding <span style="color: #66cc66;">=</span> lighty.request<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Accept-Encoding&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">or</span> <span style="color: #ff0000;">&quot;no_acceptance&quot;</span>
    cached_page <span style="color: #66cc66;">=</span> lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.doc-root&quot;</span><span style="color: #66cc66;">&#93;</span> .. <span style="color: #ff0000;">&quot;/wp-content/cache/supercache/&quot;</span> .. lighty.request<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Host&quot;</span><span style="color: #66cc66;">&#93;</span> .. lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;request.uri&quot;</span><span style="color: #66cc66;">&#93;</span> .. <span style="color: #ff0000;">&quot;/index.html&quot;</span>
    cached_page <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">string.gsub</span><span style="color: #66cc66;">&#40;</span>cached_page, <span style="color: #ff0000;">&quot;//&quot;</span>, <span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string.find</span><span style="color: #66cc66;">&#40;</span>accept_encoding, <span style="color: #ff0000;">&quot;gzip&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
      <span style="color: #b1b100;">if</span> <span style="color: #b1b100;">not</span> serve_gzip<span style="color: #66cc66;">&#40;</span>cached_page<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span> serve_html<span style="color: #66cc66;">&#40;</span>cached_page<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">end</span>
    <span style="color: #b1b100;">else</span>
      serve_html<span style="color: #66cc66;">&#40;</span>cached_page<span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">end</span>
  <span style="color: #b1b100;">end</span>
<span style="color: #b1b100;">end</span></pre></td></tr></table></div>


<p>这个lua脚本源自<a href="http://tempe.st/2008/05/lightning-speed-wordpress-with-lighttpd-and-supercache-part-ii/" title="">tempe.st</a>和<a href="http://www.thedomz.com/webmaster/2008/11/15/getting-wp-super-cache-to-work-with-lighttpd/" title="">thedomz.com</a>，不过我对其中的第23行做了修改。原始版本永远不会对博客首页启用缓存，因为lua脚本仅在请求的原始地址不存在时才进行重定向操作，但首页也就是博客根目录总是存在的，因此也就永远不会被重定向到静态缓存。我对这一行的修改就是让脚本在请求的地址与站点根目录相同时也启用静态缓存重定向机制。</p>

<p>这样折腾完之后，调整一下站点的Permalink规则，使之不要掉进wp-super-cache的忽略规则里面，应该就可以了。在页面的html源代码最后，应该能够看到super-cache的时间戳。正常工作的wp-super-cache是不会在频繁刷新页面时每次都更新这个时间戳的。附带说一下，我这个博客是没有使用wp-super-cache的，本文提及的内容应用在了<a href="http://blog.laiyonghao.com" title="blog.laiyonghao.com">blog.laiyonghao.com</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.elias.cn/archives/328/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

