- 兩種模式
- 簡(jiǎn)單模式
- 專(zhuān)家模式
在
try_files $uri $uri/ /index.php?$args;
實(shí)現(xiàn)偽靜態(tài)的前提下,兩種模式都會(huì)生成html格式的緩存文件
壓縮頁(yè)面以便讓來(lái)訪者更快瀏覽
會(huì)在生成html緩存文件的同時(shí)生成一個(gè)gz壓縮包-
到期時(shí)間和垃圾回收器
根據(jù)設(shè)定來(lái)清理緩存。
定時(shí)器選項(xiàng)會(huì)在動(dòng)態(tài)頁(yè)面訪問(wèn)時(shí)判斷是否達(dá)到定時(shí)器間隔的時(shí)間舞箍,如果達(dá)到了間隔的時(shí)間就清理一次緩存(所有緩存超時(shí)的文件)和簸。
時(shí)間選項(xiàng)會(huì)在動(dòng)態(tài)頁(yè)面被訪問(wèn)時(shí)判斷是否達(dá)到設(shè)定的時(shí)間且緩存文件是否未清理媒楼,如果都兩個(gè)都滿(mǎn)足就清理一次緩存(所有緩存超時(shí)的文件)仁卷。 實(shí)現(xiàn)真靜態(tài)
主機(jī)規(guī)則地址:https://wordpress.org/support/article/nginx/#wp-super-cache-rules
# WP Super Cache rules.
# Designed to be included from a 'wordpress-ms-...' configuration file.
set $cache_uri $request_uri;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $cache_uri 'null cache';
}
if ($query_string != "") {
set $cache_uri 'null cache';
}
# Don't cache uris containing the following segments
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';
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
set $cache_uri 'null cache';
}
# START MOBILE 如果手機(jī)端不需要緩存就把注釋去掉
# Mobile browsers section to server them non-cached version. COMMENTED by default as most modern wordpress themes including twenty-eleven are responsive. Uncomment config lines in this section if you want to use a plugin like WP-Touch
# if ($http_x_wap_profile) {
# set $cache_uri 'null cache';
#}
#if ($http_profile) {
# set $cache_uri 'null cache';
#}
#if ($http_user_agent ~* (2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800)) {
# set $cache_uri 'null cache';
#}
#if ($http_user_agent ~* (w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-)) {
# set $cache_uri 'null cache';
#}
#END MOBILE
# Use cached or actual file if they exists, otherwise pass request to WordPress
location / {
try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?$args ;
}
其中try_files /wp-content/cache/supercache/$http_host/$request_uri/index.html $uri $uri/ /index.php?$args;
,如果在本地測(cè)試且主機(jī)帶有端口就把$http_host
換成$host
需要注意的是岖瑰,wp super cache 的垃圾回收器需要訪問(wèn)動(dòng)態(tài)頁(yè)面才能觸發(fā),在rewrite后,如果被訪客訪問(wèn)的頁(yè)面均已被緩存志珍,那么訪問(wèn)的都是靜態(tài)文件。若沒(méi)有評(píng)論觸發(fā)緩存更新或管理員沒(méi)有手動(dòng)清除緩存,緩存將不會(huì)清理唤冈,也就不會(huì)更新。
5.簡(jiǎn)單與專(zhuān)家模式區(qū)別
沒(méi)看源碼不知道银伟,但是使用體驗(yàn)是一致的你虹,不論勾選簡(jiǎn)單模式還是專(zhuān)家模式都可以實(shí)現(xiàn)真靜態(tài)。
總結(jié):流量不大用緩存插件彤避。當(dāng)流量很大傅物,數(shù)據(jù)很多的時(shí)候,緩存插件的作用就不那么大了琉预,應(yīng)該考慮從項(xiàng)目整體來(lái)優(yōu)化董饰。