我对 Nginx 缓存有疑问
这是我的 Nginx 配置
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=fpmcache:100m max_size=70g inactive=3d use_temp_path=off;
server {
listen 80;
server_name example.net;
root /var/www/mydomain;
index index.php;
set $original_path $request_uri;
if ($request_uri ~ "^([^?]*)(\?.*)?$") {
set $original_path $1;
}
location / {
try_files $uri $uri/ /index.php;
}
location ~* \.(css|js|gif|jpeg|jpg|png|ico)$ {
expires max;
log_not_found off;
access_log off;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location ~ \.php$ {
fastcgi_hide_header "Set-Cookie";
add_header X-Cache $upstream_cache_status-$ua_device;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_cache_key "$original_path";
fastcgi_cache fpmcache;
fastcgi_cache_valid 200 3d;
fastcgi_cache_min_uses 1;
fastcgi_cache_lock on;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我尝试点击我的网址http://example.net/hello-world
当 nginx 使用此配置处理 url 时,缓存键为“/hello-world”
set $original_path $request_uri;
if ($request_uri ~ "^([^?]*)(\?.*)?$") {
set $original_path $1;
}
使用 ISP 1
第一次尝试 X-Cache 是 MISS 第二次尝试 X-Cache 是 HIT
使用 ISP 2
第一次尝试是MISS
为什么当我使用 ISP 2 时缓存是 MISS ..?而以前使用 ISP 1 X-Cache 很受欢迎。
我尝试调试 $original_path 变量到 access.log 是 print /hello-world