加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

nginx – FastCGI缓存始终是MISS

发布时间:2020-12-13 21:13:36 所属栏目:Nginx 来源:网络整理
导读:所以,我设置了FastCGI缓存,如下所示: location ~ .php(/.*)?${ fastcgi_cache RWI; fastcgi_cache_valid 200 60m; set $nocache 0; if ($request_method = POST) { set $nocache 1; } if ($http_cookie ~ (rwi_userid*|rwi_password*)) { set $nocache 1;

所以,我设置了FastCGI缓存,如下所示:

location ~ .php(/.*)?${
    fastcgi_cache RWI;
    fastcgi_cache_valid 200 60m;

    set $nocache 0;
    if ($request_method = POST)
    {
        set $nocache 1;
    }

    if ($http_cookie ~ (rwi_userid*|rwi_password*)) {
        set $nocache 1;
    }

    if ($request_uri ~* "/(vb/admincp/)") {
        set $nocache 1;
    }

    fastcgi_no_cache $nocache;
    fastcgi_cache_bypass $nocache;

    fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_pass "unix:/var/www/vhosts/system/{domain}/php-fpm.sock";
    include /etc/nginx/fastcgi.conf;
}

在服务器{}块之上,我有:

fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=RWI:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
add_header X-Cache $upstream_cache_status;

问题是我的PHP脚本(vBulletin)总是发送一个Pragma& Cache-Control私有.当上述规则不适用时,有没有办法忽略这些标题并强制FastCGI使用缓存?我有点迷失在这种缓存的可能性中.

最佳答案
当用作反向代理以满足HTTP中间缓存规范时,Nginx会解释一堆头文件.这意味着以下标头(如果您的应用程序回复中存在)将更改缓存行为,如下所述:

  • The “X-Accel-Expires” header field sets caching time of a response in
    seconds. The zero value disables caching for a response. If the value
    starts with the @ prefix,it sets an absolute time in seconds since
    Epoch,up to which the response may be cached.

  • If the header does not
    include the “X-Accel-Expires” field,parameters of caching may be set
    in the header fields “Expires” or “Cache-Control”.

  • If the header
    includes the “Set-Cookie” field,such a response will not be cached.

  • If the header includes the “Vary” field with the special value “*”,
    such a response will not be cached (1.7.7). If the header includes the
    “Vary” field with another value,such a response will be cached taking
    into account the corresponding request header fields (1.7.7).

但是,nginx附带fastcgi_ignore_headers指令,以防您想关闭它.所以你要找的是:fastcgi_ignore_headers Cache-Control Pragma;.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读