为啥我 Nginx 下启用 fastcgi_cache 不生成缓存?

2017-08-06 14:39:46 +08:00
 cpublic
先说说我在 nginx.conf 里 http 里的配置,如下:

fastcgi_cache_path /var/domain_cache levels=1:2 keys_zone=domain:100m inactive=1d max_size=5G;
fastcgi_temp_path /var/cache_temp;
fastcgi_cache_key "$scheme$request_method$host$request_uri"; #定义哪些情况下用过期缓存
fastcgi_cache_use_stale error timeout invalid_header http_500 http_503 updating;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie Vary;
然后是我的域名 myhost.conf 文件内的 Fastcgi_cache 有关配置,如下:

set $skip_cache 0;

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 ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
add_header X-Cache-Status $upstream_cache_status;
add_header X-Cache "$upstream_cache_status From $host";
fastcgi_cache domain;
fastcgi_cache_valid 200 301 302 1d;
}

location ~ /purge(/.*) {
allow 127.0.0.1;
allow "111.112.113.114";
deny all;
fastcgi_cache_purge domain "$scheme$request_method$host$1";
}

location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}

location = /robots.txt { access_log off; log_not_found off; }
location ~ /\. { deny all; access_log off; log_not_found off; }
WordPress 里安装了 nginx-helper 插件,通过 tailf 命令查看这个插件生成的.log 文件一直是如下显示:

https://segmentfault.com/img/bVSke7?w=284&h=231
2615 次点击
所在节点    NGINX
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/380806

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX