WP-Super-Cache专家模式WordPress伪静态规则配置

配置Wordpress wp Super Cache缓存插件Mod_Rewrite缓存模式下WordPress伪静态规则配置,配置后可绕过 PHP 直接由 Nginx 返回 HTML 页面,能大大提高网站的并发能力和速度。实现极致WordPress优化

WP-Super-Cache专家模式WordPress伪静态规则配置

这份规则如下,替换 WordPress 原本的伪静态规则即可(已修改同时兼容HTTPS/HTTP,并增加是否命中的 Nginx-Static 头)。

(转载自https://hzbk.net/archives/1019.html,感谢站长分享)

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

相关文章请点击文末标签阅读!

给TA打赏
共{{data.count}}人
人已打赏
网站建设

wp网站7B2主题美化之圈子新手引导特效

2022-7-17 22:09:24

网站建设

WordPress网站B2主题美化之文章底部添加所属专题

2023-3-29 9:08:53

🚨 小黑屋
  1. 为啥添加专用规则,感觉变卡了?

    • 默认的好像能快点😢

    • 哈哈,这个是专家模式,从原理上看是将缓存文件从nginx直接读取,应该是更快的。不过还有个小问题就是吃服务器内存,如果数据量大,内存卡顿也是会变慢的

    • 感谢解惑。

  2. 再次学习了!博主强大

    • 谢谢夸奖,单纯经验分享

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索