为nginx设置wordpress插件supercache的rewrite规则
Wordpress的Supercache插件相信玩wordpress的兄弟都知道,它通过生成静态页面并压缩输出来提升访问速度。不过插件作者只制作了基于apache虚拟主机的url rewrite规则,对于现在很多用nginx主机的人来说,就需要自己来写规则了。今天大致研究了一下,得出了一个我自己的方案,可以实现nginx支持supercache的重写。
要实现这个功能,你的nginx必须编译了pcre支持(用来支持url rewrite),以及gzip支持(对应编译参数 –with-http_gzip_static_module),否则下面的一切都是空谈。
下面这一段配置,你可以加入到你需要进行设置的虚拟主机配置文件中。注意以下几点:
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 44 | location / { autoindex off; gzip_static on; set $wp_super_cache_file ''; set $wp_super_cache_uri $request_uri; if ( $request_method = POST ) { set $wp_super_cache_uri ''; } if ( $query_string ) { set $wp_super_cache_uri ''; } if ( $http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) { set $wp_super_cache_uri ''; } if ( $wp_super_cache_uri ~ ^(.+)$ ) { set $wp_super_cache_file /wp-content/cache/wp_super_cache/$http_host/$1index.html; } if ( -f $document_root$wp_super_cache_file ) { rewrite ^(.*)$ $wp_super_cache_file break; } if (-f $request_filename) { expires 30d; break; } if (!-e $request_filename) { rewrite ^(.+)$ /index.php?q=$1 last; } } |
下载文件:
nginx-wordpress-supercache (1.4 KiB, 72 hits)
You need to be a registered user to download this file.

因为这句话,都不能启动Nginx了,删除了就没问题
但是,发表一个评论以后,不会自动更新缓存 郁闷的说 博主怎么联系你?有QQ或者Gtalk之类的么?