记录WordPress在Nginx下的supercache规则设置

购买了linode vps 后,就开始测试wordpress在nginx运行的问题了,其中一个就是WordPress在Nginx下的supercache规则设置, 参考了网上N位的经验后,按以下设置成功,特意记录下,看来nginx已经开始时主流了.

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去. 加进server{…xxx…}中间.

我把上述代码保存成一个叫supercache.conf的文件,然后再nginx.conf段里添加上去,就是像下边这样

server
{
listen 80;
server_name www.lpfrx.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/mywww/www.lpfrx.com;
include supercache.conf;

location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*\.(js|css)?$
{
expires 12h;
}

log_format www.lpfrx.com ‘$remote_addr – $remote_user [$time_local] $request ‘
‘$status $body_bytes_sent $http_referer ‘
‘$http_user_agent $http_x_forwarded_for’;
access_log www.lpfrx.com.log www.lpfrx.com;
}

关于无聊人

一个无聊人而已
此条目发表在nginx分类目录,贴了标签。将固定链接加入收藏夹。

记录WordPress在Nginx下的supercache规则设置》有2条回应

  1. 小木刀说:

    是不是装了这个规则就行了?

    我刚买的linode只添了一段server,不会写别的,改动一下永久链接就会404,请教一下要怎么写呢?

  2. 无聊人说:

    是的,不过你要知道添加在哪里

发表回复

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