全球主机交流论坛

标题: 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规则。。
  1. # BEGIN supercache
  2. <IfModule mod_mime.c>
  3.   <FilesMatch "\.html\.gz$">
  4.     ForceType text/html
  5.     FileETag None
  6.   </FilesMatch>
  7.   AddEncoding gzip .gz
  8.   AddType text/html .gz
  9. </IfModule>
  10. <IfModule mod_deflate.c>
  11.   SetEnvIfNoCase Request_URI \.gz$ no-gzip
  12. </IfModule>
  13. <IfModule mod_headers.c>
  14.   Header set Vary "Accept-Encoding, Cookie"
  15.   Header set Cache-Control 'max-age=300, must-revalidate'
  16. </IfModule>
  17. <IfModule mod_expires.c>
  18.   ExpiresActive On
  19.   ExpiresByType text/html A300
  20. </IfModule>

  21. # 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
差不多,我放的代码如下:
  1.                 set $supercache_file '';
  2.                 set $supercache_uri $request_uri;

  3.                 if ($request_method = POST) {
  4.                 set $supercache_uri '';
  5.                 }

  6.                 # Using pretty permalinks, so bypass the cache for any query string
  7.                 if ($query_string) {
  8.                 set $supercache_uri '';
  9.                 }

  10.                 if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) {
  11.                 set $supercache_uri '';
  12.                 }

  13.                 # if we haven't bypassed the cache, specify our supercache file
  14.                 if ($supercache_uri ~ ^(.+)$) {
  15.                 set $supercache_file /home/www/heibaihui.net/wp-content/cache/supercache/$http_host/$1index.html;
  16.                 }

  17.                 # only rewrite to the supercache file if it actually exists
  18.                 if (-f $document_root$supercache_file) {
  19.                 rewrite ^(.*)$ $supercache_file break;
  20.                 }

  21.                 # all other requests go to Wordpress
  22.                 if (!-e $request_filename) {
  23.                 rewrite . /home/www/heibaihui.net/index.php last;
  24.                 }
复制代码
如果放上这个会报错,不知道怎么回事。

# 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不用管

[ 本帖最后由 gdtv 于 2009-11-10 11:33 编辑 ]
作者: cpuer    时间: 2009-11-10 11:54
标题: 回复 10# 的帖子
看到了,/$1index和$1/index

作者: rdpof    时间: 2009-11-10 13:44
明白了,我设置来设置去,缓存都不管用。

一郁闷就删了。

准备改用cos-html-cache,好象这个不错,直接生成HTML,MYSQL挂了都不影响网站。

设置简单,国人开发。
作者: cpuer    时间: 2009-11-10 13:52
标题: 回复 12# 的帖子
但是生成html的话会额外占用磁盘空间,有评论也要重新生成吧,也不是很方便。
作者: gdtv    时间: 2009-11-10 13:56
原帖由 cpuer 于 2009-11-10 13:52 发表
但是生成html的话会额外占用磁盘空间,有评论也要重新生成吧,也不是很方便。

WP Super Cache也一样
作者: pigicoffee    时间: 2009-11-10 14:00
gzip_static on;  我汗 这个问题只要编译的时候后面加上 --with-http_gzip_static_module就可以解决了
作者: cpuer    时间: 2009-11-10 14:00
标题: 回复 14# 的帖子
有评论也要重新生成 ?
作者: cpuer    时间: 2009-11-10 14:02
nginx必须编译了pcre支持(用来支持url rewrite),以及gzip支持(对应编译参数 –with-http_gzip_static_module)

才能完全支持WP Super Cache 好像,网络上搜的。
作者: rdpof    时间: 2009-11-10 14:03
有评论会自动生成,目前看来,还是比较满意的。

就生成几个HTML,花不了多少磁盘吧。
作者: pigicoffee    时间: 2009-11-10 14:03
pcre本来就需要 不然wp的伪静态也弄不了了
作者: cpuer    时间: 2009-11-10 16:00
标题: 回复 18# 的帖子
解决了问题就好




欢迎光临 全球主机交流论坛 (https://443502.xyz/) Powered by Discuz! X3.4