您現在的位置是:首頁 > 動作武俠首頁動作武俠

極限加速:WordPress全站靜態化,實現頁面0SQL查詢

簡介} # 對登入使用者或已釋出評論使用者不使用快取#if ($http_cookie ~* “comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in”) {#

驚羽的師傅是黑衣人嗎

WordPress站點如何做到頁面秒開,最簡單最快速的方法就是生成靜態html檔案了,這種方法可以實現頁面0SQL查詢(除搜尋及評論外)。下面我將本站採用的方法分享給大家,或許能給大家最佳化自己的WordPress站點提供一些思路。

本站採用靜態化html生成外掛Simply Static+Nginx搭配使用。

Simply Static用來生成html檔案,關於這個外掛的設定就不展示了,很簡單的,設定儲存模式為本地目錄儲存。

我重點說一下Nginx的配置:

set $cache_uri $request_uri;# 請求方式為post時不使用快取if ($request_method = POST) { set $cache_uri ‘null cache’;}if ($query_string != “”) { set $cache_uri ‘null cache’;} # uri包含以下內容時不使用快取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’;} # 對登入使用者或已釋出評論使用者不使用快取#if ($http_cookie ~* “comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in”) {# set $cache_uri ‘null cache’;#}# 如果存在快取,則使用快取,如果沒有快取,直接轉向動態頁面location /{ try_files /*html檔案目錄*/$cache_uri/index。html $uri $uri/ /index。php?$args ;}rewrite /wp-admin$ $scheme://$host$uri/ permanent;

將以上程式碼中的 *html檔案目錄* 修改為你自己設定的目錄路徑並放入網站Nginx配置檔案。

除此之外,還要設定禁止訪問html檔案目錄,否則使用者就可以直接訪問這個目錄的html檔案了。

location ^~ /*html檔案目錄*/ { return 404; } location ^~ /wp-content/plugins/simply-static/static-files/ { return 404; }

至此所有設定都已完成。需要注意的是Simply Static外掛每次生成html檔案都不會覆蓋原來的html檔案,所以每次生成html檔案之前都需要手動刪除原來的html檔案。

搭配如何使用CDN加速WordPress網站靜態資源 大默無言使用更美好喲!

極限加速:WordPress全站靜態化,實現頁面0SQL查詢 – 大默無言

Top