Nginx缓存密钥$uri可以';t区分URL';s
我正在使用nginx缓存我的站点。然而,默认的fastcgi_缓存_密钥选项“$scheme$request\u method$host$request\u uri”对我来说并不好,因为我使用我的站点进行付费流量,并且它发送了许多类似UTM的参数 我想忽略参数,所以我将$request_uri更改为$uri 但现在,当我重新加载nginx时,我尝试访问一个随机页面,它将显示标题:“x-cache:MISS”,并正确显示此页面。但现在每次我尝试访问任何页面时,它都会显示我访问的第一个页面和“x-cache:HIT”,即使是不存在的页面,它也会显示第一个页面 我的确认:Nginx缓存密钥$uri可以';t区分URL';s,nginx,caching,fastcgi,Nginx,Caching,Fastcgi,我正在使用nginx缓存我的站点。然而,默认的fastcgi_缓存_密钥选项“$scheme$request\u method$host$request\u uri”对我来说并不好,因为我使用我的站点进行付费流量,并且它发送了许多类似UTM的参数 我想忽略参数,所以我将$request_uri更改为$uri 但现在,当我重新加载nginx时,我尝试访问一个随机页面,它将显示标题:“x-cache:MISS”,并正确显示此页面。但现在每次我尝试访问任何页面时,它都会显示我访问的第一个页面和“x-c
fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=WP:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
server {
listen 80;
listen [::]:80;
server_name example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
root /var/www/html/example.com;
index index.php;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
error_log /var/log/nginx/example.com_error.log;
access_log /var/log/nginx/example.com_access.log;
client_max_body_size 1024M;
add_header X-Cache $upstream_cache_status;
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
set $skip_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
#set $skip_cache 1;
}
# Don't cache uris containing the following segments
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
set $skip_cache 1;
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|mp3|ogg|ogv|webm|htc|woff2|woff)$ {
expires 1M;
access_log off;
# max-age must be in seconds
add_header Cache-Control "max-age=2629746, public";
}
# CSS and Javascript
location ~* \.(?:css|js)$ {
expires 1y;
access_log off;
add_header Cache-Control "max-age=31556952, public";
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_cache WP;
fastcgi_cache_valid 200 60m;
fastcgi_cache_methods GET HEAD;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
}
}
非常感谢你,我的英语很抱歉