前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >WordPress WP-Super-Cache 缓存插件 Nginx 规则

WordPress WP-Super-Cache 缓存插件 Nginx 规则

原创
作者头像
Breeze.
修改2023-02-16 22:58:46
7900
修改2023-02-16 22:58:46
举报

WP-Super-Cache 作为 WordPress 的老牌静态缓存插件,它在 WordPress.Org 的一个角落一直有一份 Nginx 伪静态规则(Nginx – WordPress.org Forums)。

配置后可绕过 PHP 直接由 Nginx 返回 HTML 页面,能大大提高网站的并发能力和速度。

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

?复制

代码语言:javascript
复制
# 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;

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
作者已关闭评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
网站建设
网站建设(Website Design Service,WDS),是帮助您快速搭建企业网站的服务。通过自助模板建站工具及专业设计服务,无需了解代码技术,即可自由拖拽模块,可视化完成网站管理。全功能管理后台操作方便,一次更新,数据多端同步,省时省心。使用网站建设服务,您无需维持技术和设计师团队,即可快速实现网站上线,达到企业数字化转型的目的。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com