nginx+wp-super-cache不生成静态cache文件

网站迁移到nginx后,所有原来apache下面的配置文件都要重新写。
配置完wp-super-cache后,查看后台,发现cache目录已经建立,但是没有生成html文件。
打开wp-super-cache的debug功能,查看后台log

00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Cookie detected: wordpress_logged_in_08459be021d7ddc91806841039286bce
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ No wp-cache file exists. Must generate a new one.
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Cookie detected: wordpress_logged_in_08459be021d7ddc91806841039286bce
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ In WP Cache Phase 2
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Setting up WordPress actions
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Supercache caching disabled. Only using wp-cache. Non empty GET request.
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Created output buffer
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Output buffer callback
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Supercache disabled: GET or feed detected or disabled by config.
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Writing non-gzipped buffer to wp-cache cache file.

发现是因为有GET参数传递给了wp-super-cache,所以disabled.
wordpress所有响应都是rewrite给index.php的,检查nginx rewrite规则。发现确实使用用参数传递给index.php的,

try_files $uri/ $uri /index.php?q=$uri&$args;

网上查找一下,换成如下的rewrite方法

if (!-e $request_filename) { rewrite ^/(.+)$ /index.php last; }

reload配置之后,再次访问同一页面,后台trace如下

01:11:49 /2012/06/27/yourls-rewrite-apache-to-nginx/ Sending buffer to browser
01:11:49 /2012/06/27/yourls-rewrite-apache-to-nginx/ wp_cache_shutdown_callback: collecting meta data.
01:11:49 /2012/06/27/yourls-rewrite-apache-to-nginx/ Did not write meta file: wp-cache-6848e4f0747fac2d2b5b769950bff440.meta *1* *0* *1*
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ supercache dir: /****/public_html/wp-content/cache/supercache/3qs.com/2012/06/27/yourls-rewrite-apache-to-nginx/
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ No wp-cache file exists. Must generate a new one.
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ In WP Cache Phase 2
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Setting up WordPress actions
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Created output buffer
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Output buffer callback
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Anonymous user detected. Only creating Supercache file.
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Writing non-gzipped buffer to supercache file.
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Renamed temp supercache file to /****/public_html/wp-content/cache/supercache/3qs.com/2012/06/27/yourls-rewrite-apache-to-nginx/index.html
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Sending buffer to browser
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ wp_cache_shutdown_callback: collecting meta data.

到后台服务器上产看, 已经生成了对应的index.html静态文件了,访问速度也从1500多ms降到500多ms,多次访问,会返回304,在本地也cache了。。

[09:17:41.414] GET http://3qs.com/2012/06/27/yourls-rewrite-apache-to-nginx/ [HTTP/1.1 304 Not Modified 204ms]

-THE END-

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>