NGINX下可用的WP super cache规则

最近把BLOG的缓存换成了WP super cache,但是这个插件默认是运行在APACHE下面的,根据各种度娘谷歌后找到了对应的NGINX下的规则。
1.简洁形:

location / {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}

2.完整形:

location / 
{ 

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; 
} 
}

说实话,对于这两种规则的区别不大搞得清,但是经测试都是可以用的,而且根据查看源码显示的都能正确读取到缓存,具体用哪一种就看自己的喜好了。

One Reply to “NGINX下可用的WP super cache规则”

发表回复

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


此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据