繁体   English   中英

Nginx-如果响应状态为200,如何为特定路径增加fastcgi_cache_valid?

[英]Nginx - how to increase fastcgi_cache_valid for a certain path if response status is 200?

我在网站上有某个路径,例如/static/1234 ,并且当nginx从fastcgi php后端请求这样的路径时,我希望将其缓存更长的时间,但前提是响应状态为200。所有其他页面应使用默认的缓存设置。

目前,我有以下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 ,所以增加缓存有效时间是行不通的。

我该如何运作?

最后,对我X-Accel-Expires的解决方案是在static控制器的php代码中将X-Accel-Expires标头设置为较高的值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM