與我們合作
我們專注:網站策劃設計、網絡輿論監控、網站優化及網站營銷、品牌策略與設計
主營業務:網站建設、移動端微信小程序開發、APP開發、網絡運營、云產品·運維解決方案
有一個品牌項目想和我們談談嗎?
您可以填寫右邊的表格,讓我們了解您的項目需求,這是一個良好的開始,我們將會盡快與您取得聯系。當然也歡迎您給我們寫信或是打電話,讓我們聽到您的聲音
您也可通過下列途徑與我們取得聯系:
地 址: 上海市長寧區華寧國際7L
電 話: 400-825-2717(咨詢專線)
電 話: 13054973230(售后客戶服務)
傳 真: 021-61488448
郵 箱: admin@wumujituan.com
快速提交您的需求 ↓
WordPress WP-Super-Cache 緩存插件 Nginx 優化規則
發布日期:2023-12-19 瀏覽次數:37511
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 頭)。
# 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;
自用備存,轉自wepublish的耗子博客。

