搜索
网站建设,网站优化,网络营销,app开发,小程序开发,全网营销

400-825-2717互联网开发&推广服务提供商

与我们合作

我们专注:网站策划设计、网络舆论监控、网站优化及网站营销、品牌策略与设计
主营业务:网站建设、移动端微信小程序开发、APP开发、网络运营、云产品·运维解决方案

有一个品牌项目想和我们谈谈吗?

您可以填写右边的表格,让我们了解您的项目需求,这是一个良好的开始,我们将会尽快与您取得联系。当然也欢迎您给我们写信或是打电话,让我们听到您的声音

您也可通过下列途径与我们取得联系:

地 址: 上海市长宁区华宁国际7L

电 话: 400-825-2717(咨询专线)

电 话: 13054973230(售后客户服务)

网 址: http://www.56gw.net

传 真: 021-61488448

邮 箱: admin@wumujituan.com

快速提交您的需求 ↓

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

发布日期:2023-12-19 浏览次数:21117

WP-Super-Cache 作为 WordPress 的老牌静态缓存插件,它在 WordPress.Org 的一个角落一直有一份 Nginx 伪静态规则(https://wordpress.org/support/article/nginx/#wp-super-cache-rules)。
配置后可绕过 PHP 直接由 Nginx 返回 HTML 页面,能大大提高网站的并发能力和速度。
这份规则如下,替换 WordPress 原本的伪静态规则即可(已修改同时兼容 HTTPS/HTTP,并增加是否命中的 Nginx-Static 头)。

  1. # WP Super Cache 规则


  2. set $cache_uri $request_uri;

  3. set $nginx_static 'BYPASS For File';


  4. # POST 请求不读取缓存

  5. if ($request_method = POST)

  6. {

  7.     set $cache_uri 'null cache';

  8.     set $nginx_static 'BYPASS For POST';

  9. }


  10. # 查询请求不读取缓存

  11. if ($query_string != "")

  12. {

  13.     set $cache_uri 'null cache';

  14.     set $nginx_static 'BYPASS For Query';

  15. }


  16. # 特定页面不读取缓存

  17. 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)")

  18. {

  19.     set $cache_uri 'null cache';

  20.     set $nginx_static 'BYPASS For URL';

  21. }


  22. # 特定 Cookie 不读取缓存

  23. if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in|woocommerce_items_in_cart|woocommerce_cart_hash|wptouch_switch_toogle")

  24. {

  25.     set $cache_uri 'null cache';

  26.     set $nginx_static 'BYPASS For Cookie';

  27. }


  28. # 判断缓存是否存在

  29. if (-f $document_root/wp-content/cache/supercache/$http_host/$cache_uri/index-https.html)

  30. {

  31.     set $nginx_static 'HIT';

  32. }

  33. if (-f $document_root/wp-content/cache/supercache/$http_host/$cache_uri/index.html)

  34. {

  35.     set $nginx_static 'HIT';

  36. }


  37. location /

  38. {

  39.     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;

  40. }


  41. add_header Nginx-Static $nginx_static;

  42. rewrite /wp-admin$ $scheme://$host$uri/ permanent;


自用备存,转自wepublish的耗子博客。


GO 知识
查看经典案例

TOP

QQ客服

免费电话

微信咨询 在线咨询 免费电话
获取报价
您的称呼:

*

您的电话:

*

您的邮箱:

*

提交 重置
重要的事情,电话里聊

接通客服

不方便的时候线上咨询,在线等哦