标题: WP Super Cache的重写规则 [打印本页] 作者: rdpof 时间: 2009-11-10 09:54 标题: WP Super Cache的重写规则 wordpress来顶2.5K的访问量,觉得有点吃力了。
一般并发都在40-50之间,造成CPU的使用率较高。访问高峰的时候,差不多15-20%。
我怕他们一不高兴就把我的VPS关了,所以想办法优化一下。
今早装了WP Super Cache,其他都设置好了,唯独后台后台提示Mod rewrite may not be installed!
重写规则没弄好,代沟有没有兄弟也用这个?Nginx下的WP Super Cache重写规则是多少?作者: rdpof 时间: 2009-11-10 09:55
贴出它自动生成的apache规则。。
# BEGIN supercache
<IfModule mod_mime.c>
<FilesMatch "\.html\.gz$">
ForceType text/html
FileETag None
</FilesMatch>
AddEncoding gzip .gz
AddType text/html .gz
</IfModule>
<IfModule mod_deflate.c>
SetEnvIfNoCase Request_URI \.gz$ no-gzip
</IfModule>
<IfModule mod_headers.c>
Header set Vary "Accept-Encoding, Cookie"
Header set Cache-Control 'max-age=300, must-revalidate'
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html A300
</IfModule>
# END supercache
复制代码
作者: dongzide 时间: 2009-11-10 10:05
不懂,我win主机用 wp super cache啥也没提示啊,用的好好的作者: pigicoffee 时间: 2009-11-10 10:07
maybe later when i got home i will post mine~~作者: rdpof 时间: 2009-11-10 10:15
ok,tks作者: lemss 时间: 2009-11-10 10:19
总觉得WordPress不适合大应用,占资源太多作者: ABC 时间: 2009-11-10 10:27 http://forum.slicehost.com/comments.php?DiscussionID=2087作者: rdpof 时间: 2009-11-10 10:30
差不多,我放的代码如下:
set $supercache_file '';
set $supercache_uri $request_uri;
if ($request_method = POST) {
set $supercache_uri '';
}
# Using pretty permalinks, so bypass the cache for any query string
if ($query_string) {
set $supercache_uri '';
}
if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) {
set $supercache_uri '';
}
# if we haven't bypassed the cache, specify our supercache file
if ($supercache_uri ~ ^(.+)$) {
set $supercache_file /home/www/heibaihui.net/wp-content/cache/supercache/$http_host/$1index.html;
}
# only rewrite to the supercache file if it actually exists
if (-f $document_root$supercache_file) {
rewrite ^(.*)$ $supercache_file break;
}
# all other requests go to Wordpress
if (!-e $request_filename) {
rewrite . /home/www/heibaihui.net/index.php last;
}
复制代码
如果放上这个会报错,不知道怎么回事。
# if the requested file exists, return it immediately
if (-f $request_filename) {
break;
}作者: cpuer 时间: 2009-11-10 10:59 标题: 回复 1# 的帖子 好像用 WP Super Cache的话整个规则要改写,报错的话哪行的错误?
参考:
location / {
# enable search for precompressed files ending in .gz
# nginx needs to be complied using –-with-http_gzip_static_module
# for this to work, comment out if using nginx from aptitude
gzip_static on;
# if the requested file exists, return it immediately
if (-f $request_filename) {
break; }
set $supercache_file '';
set $supercache_uri $request_uri;
if ($request_method = POST) {
set $supercache_uri '';
}
# Using pretty permalinks, so bypass the cache for any query string
if ($query_string) {
set $supercache_uri '';
}
if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) {
set $supercache_uri '';
}
# if we haven't bypassed the cache, specify our supercache file
if ($supercache_uri ~ ^(.+)$) {
set $supercache_file /blog/wp-content/cache/supercache/$http_host/$1index.html;
}
# only rewrite to the supercache file if it actually exists
if (-f $document_root$supercache_file) {
rewrite ^(.*)$ $supercache_file break;
}
# all other requests go to Wordpress
if (!-e $request_filename) {
rewrite . /blog/index.php last;
}
}作者: gdtv 时间: 2009-11-10 11:30
这是我用的规则,请注意红色部分
location / {
# gzip_static on;
# if the requested file exists, return it immediately
if (-f $request_filename) {
break;
}
set $supercache_file '';
set $supercache_uri $request_uri;
if ($request_method = POST) {
set $supercache_uri '';
}
# Using pretty permalinks, so bypass the cache for any query string
if ($query_string) {
set $supercache_uri '';
}
if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) {
set $supercache_uri '';
}
# if we haven't bypassed the cache, specify our supercache file
if ($supercache_uri ~ ^(.+)$) {
set $supercache_file /wp-content/cache/supercache/$http_host$1/index.html;
}
# only rewrite to the supercache file if it actually exists
if (-f $document_root$supercache_file) {
rewrite ^(.*)$ $supercache_file break;
}
# all other requests go to Wordpress
if (!-e $request_filename) {
rewrite . /index.php last;
}
}
1、"# gzip_static on;" 这个我的nginx不支持,所以要注释掉
2、网上所有教程都是"set $supercache_file /wp-content/cache/supercache/$http_host/$1index.html;",但在我的VPS上用了这个不行,有些页面不能缓存,经测试改成了这样:"set $supercache_file /wp-content/cache/supercache/$http_host$1/index.html;",注意有个斜杆的位置不同。
3、后台提示Mod rewrite may not be installed不用管