全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

IP归属甄别会员请立即修改密码
查看: 2644|回复: 19
打印 上一主题 下一主题

[疑问] WP Super Cache的重写规则

[复制链接]
跳转到指定楼层
1#
发表于 2009-11-10 09:54:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
wordpress来顶2.5K的访问量,觉得有点吃力了。

一般并发都在40-50之间,造成CPU的使用率较高。访问高峰的时候,差不多15-20%。

我怕他们一不高兴就把我的VPS关了,所以想办法优化一下。

今早装了WP Super Cache,其他都设置好了,唯独后台后台提示Mod rewrite may not be installed!

重写规则没弄好,代沟有没有兄弟也用这个?Nginx下的WP Super Cache重写规则是多少?
2#
 楼主| 发表于 2009-11-10 09:55:59 | 只看该作者
贴出它自动生成的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
复制代码
3#
发表于 2009-11-10 10:05:40 | 只看该作者
不懂,我win主机用 wp super cache啥也没提示啊,用的好好的
4#
发表于 2009-11-10 10:07:43 | 只看该作者
maybe later when i got home i will post mine~~
5#
 楼主| 发表于 2009-11-10 10:15:48 | 只看该作者
ok,tks
6#
发表于 2009-11-10 10:19:28 | 只看该作者
总觉得WordPress不适合大应用,占资源太多
7#
发表于 2009-11-10 10:27:09 | 只看该作者
8#
 楼主| 发表于 2009-11-10 10:30:43 | 只看该作者
差不多,我放的代码如下:
  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;
        }
9#
发表于 2009-11-10 10:59: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;        
}
}
10#
发表于 2009-11-10 11:30:24 | 只看该作者
这是我用的规则,请注意红色部分

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 编辑 ]

评分

参与人数 1威望 +30 收起 理由
cpuer + 30 感谢分享

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2025-9-29 05:42 , Processed in 0.133296 second(s), 14 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表