Nginx 在页面首次缓存后几个小时将 x-fastcgi-cache 标头设置为 EXPIRED,而缓存有效期为 1 周。
Nginx配置:
fastcgi_cache_path /usr/share/nginx/fastcgi_cache levels=1:2 keys_zone=phpcache:500m max_size=30g inactive=1w use_temp_path=off;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_cache_valid 1w;
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
...
set $skip_cache 0;
set $bypass_reason "NONE";
set $woocommerce "OK";
# POST requests and URLs with a query string should always go to PHP
if ($request_method = POST) {
set $skip_cache 0;
set $bypass_reason "REQUEST_METHOD";
}
if ($request_uri ~* ("/wp-admin.*|/cart.*|/panier.*|/commander.*|/checkout.*|/account.*|/myaccount.*|/addond.*|/store.*|/shop.*|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-ocations.php|sitemap(_index)?.xml|a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
set $skip_cache 1;
set $bypass_reason "REQUEST_URI_1";
}
if ( $cookie_yith_ywraq_items_in_raq != "0" ) {
set $woocommerce "NOK";
}
if ( $cookie_yith_ywraq_items_in_raq = "" ) {
set $woocommerce "OK";
}
if ( $woocommerce = "NOK" ) {
set $skip_cache 1;
set $bypass_reason "WOOCOMMERCE";
}
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
set $skip_cache 1;
set $bypass_reason "REQUEST_URI_2";
}
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|panier|commander") {
set $skip_cache 1;
set $bypass_reason "HTTP_COOKIE";
}
location ~ \.php$ {
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache phpcache;
fastcgi_cache_valid 200 301 302 60m;
fastcgi_cache_use_stale error timeout updating invalid_header http_500 http_503;
fastcgi_cache_min_uses 1;
fastcgi_cache_lock on;
add_header X-FastCGI-Cache $upstream_cache_status;
add_header X-FastCGI-Cache-Bypass-Reason $bypass_reason;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
...
我不明白为什么即使inactive=1w
这样fastcgi_cache_valid 1w
我仍有一个过期的缓存状态。
对于我在这里遗漏了什么有什么想法吗?
谢谢
答案1
我可能记错了,但看起来您将默认过期时间设置为 1 周,但然后又将所有使用缓存的 php 请求的过期时间设置为仅 60 分钟:phpcache。
您可能试图通过将第二条线路设置为 60m 来强制执行其他到期时间,但我相信这可能是问题的根源。