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주로 설정한 다음 캐시: phpcache를 사용하여 모든 PHP 요청에 대해 다시 60분으로 설정하는 것 같습니다.
이 두 번째 줄을 60m로 설정하여 다른 만료를 적용하려고 할 수도 있지만 이것이 문제의 원인일 수 있다고 생각합니다.