0
我在網站上有一個特定的路徑,說/static/1234
,並且當nginx從fastcgi php後端請求這樣的路徑時,我希望它被緩存更長的時間,但只有當響應狀態是200時。所有其他頁面應該使用默認的緩存設置。Nginx - 如果響應狀態爲200,如何爲特定路徑增加fastcgi_cache_valid?
目前,我有以下nginx的配置:
# delete cache if hasn't been used in 40 minutes
fastcgi_cache_path /var/cache/nginx keys_zone=main:32m inactive=40m levels=2:2;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
# update cache every 30 minutes
fastcgi_cache_valid any 30m;
server {
fastcgi_cache main;
root /home/user/app/htdocs;
index index.php;
server_name test.dev;
location /static/ {
fastcgi_cache_valid 200 10d;
try_files $uri /index.php;
}
location/{
try_files $uri /index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我已經添加到$upstream_cache_status
日誌,並降低高速緩存倍到20秒和5分鐘測試此配置。但是我在20秒後看到每個URL都是EXPIRED
,所以緩存有效時間的增加不起作用。
如何讓它工作?