朋友说 WordPress 使用 WP-Super-Cache 插件早就可以实现真正的静态页面,一开始不相信,毕竟多年前用过,静态页面压根不对味。
然后朋友鄙视的告诉我,你用WP-Super-Cache 插件没陪Nginx规则,不是白瞎了这么好的插件?
Σ( ̄。 ̄ノ)ノ
WP-Super-Cache 插件需要配合Nginx规则?搜索了技术文档,居然还真是。。。
替换Nginx单纯的为静态规则就行,就是这么简单,我居然十来年后才发现,哎,技术能力堪忧。
(@_@)
# WP Super Cache 规则
set $cache_uri $request_uri;
set $nginx_static 'BYPASS For File';
# POST 请求不读取缓存
if ($request_method = POST)
{
set $cache_uri 'null cache';
set $nginx_static 'BYPASS For POST';
}
# 查询请求不读取缓存
if ($query_string != "")
{
set $cache_uri 'null cache';
set $nginx_static 'BYPASS For Query';
}
# 特定页面不读取缓存
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)")
{
set $cache_uri 'null cache';
set $nginx_static 'BYPASS For URL';
}
# 特定Cookie不读取缓存
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in|woocommerce_items_in_cart|woocommerce_cart_hash|wptouch_switch_toogle")
{
set $cache_uri 'null cache';
set $nginx_static 'BYPASS For Cookie';
}
# 判断缓存是否存在
if (-f $document_root/wp-content/cache/supercache/$http_host/$cache_uri/index-https.html)
{
set $nginx_static 'HIT';
}
if (-f $document_root/wp-content/cache/supercache/$http_host/$cache_uri/index.html)
{
set $nginx_static 'HIT';
}
location /
{
try_files /wp-content/cache/supercache/$http_host/$cache_uri/index-https.html /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?$args;
}
add_header Nginx-Static $nginx_static;
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
没有回复内容