- 添加反向代理,开启缓存
- 安装 nginx helper 插件, 选择 fast-cgi cache
- 编辑反向代理配置
#PROXY-START/ set $skip_cache 0; #post访问不缓存 if ($request_method = POST) { set $skip_cache 1; } #动态查询不缓存 if ($query_string != "") { set $skip_cache 1; } #后台等特定页面不缓存(其他需求请自行添加即可) if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") { set $skip_cache 1; } #对登录用户、评论过的用户不展示缓存 if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { set $skip_cache 1; } location ~* \.(gif|png|jpg|css|webp|js|woff|woff2)$ { proxy_pass https://127.0.0.1:1443; #apache 端口 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; expires 90h; } location / { proxy_pass https://127.0.0.1:1443; #apache 端口 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; add_header X-Cache $upstream_cache_status; #Set Nginx Cache proxy_ignore_headers Set-Cookie Cache-Control expires; proxy_cache cache_one; proxy_cache_key $host$uri$is_args$args; proxy_cache_valid 200 304 301 302 120m; #Set Nginx Cache bypass proxy_cache_bypass $skip_cache; proxy_no_cache $skip_cache; } location ~ /purge(/.*) { allow 127.0.0.1; allow "YOUR-SERVER-IP"; #本机IP deny all; proxy_cache_purge cache_one "$host$uri$is_args$args"; } #PROXY-END/