我不知道nginx中控制FastCGI缓存的插件。但是,有一组nginx规则可以直接使用WP超级缓存。
让我们想想——当访问站点页面时,会发生什么?
nginx接受请求并查看该索引。需要php
nginx启动php fpm(一点都不快)WordPress开始工作在开始时,WP Super Cache插件遇到问题并已保存滑倒。html而不是无限长的页面生成(在这些计时术语中)这都不是坏事,但是:我们需要启动php fpm,然后执行一些php代码,以保存响应。html。有一种解决方案,可以在没有php的情况下继续进行。让我们立即在nginx上重写。
编辑/etc/nginx/conf.d/servers.conf
– 以及之后index index.php;
行插入:
include snippets/wp-supercache.conf;
创建文件夹/etc/nginx/snippets
和文件wp-supercache.conf
其中包含以下内容:rewrite ^([^.]*[^/])$ $1/ permanent;
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\';
}
# Set the cache file
set $cachefile "/wp-content/cache/supercache/$http_host/$cache_uri/index.html";
set $gzipcachefile "/wp-content/cache/supercache/$http_host/$cache_uri/index.html.gz";
if ($https ~* "on") {
set $cachefile "/wp-content/cache/supercache/$http_host/$cache_uri/index-https.html";
set $gzipcachefile "/wp-content/cache/supercache/$http_host/$cache_uri/index.html.gz";
}
# Add cache file debug info as header
#add_header X-Cache-File $cachefile;
# Try in the following order: (1) gzipped cachefile, (2) cachefile, (3) normal url, (4) php
location / {
try_files $gzipcachefile $cachefile $uri $uri/ /index.php;
}
执行此指令时,nginx会自行查找(如果有)。WP Super Cache插件文件夹中的html可用(或compressed.html.gz),如果。html存在,完全不用启动任何php fpm就可以使用它。有关更多详细信息,请阅读我的文章https://kagg.eu/en/10000-clients-second-wordpress/. “在nginx中重写”一节描述了旨在与WP超级缓存插件协同工作的nginx设置。
在您的问题中,它与FastCGI缓存有点不同,但运行良好。