【问题标题】:Nginx cache bypass by custom response header通过自定义响应标头绕过 Nginx 缓存
【发布时间】:2017-08-31 16:13:22
【问题描述】:

我想通过使用自定义标头“Do-Cache”从我的脚本中实现自定义 nginx 缓存控制方法。 我在 nginx 的 http 块中使用过:

map $sent_http_do_cache $nocache {
        public 0;
        default 1;
}

并且在 nginx 的 server 块中:

fastcgi_cache_bypass $nocache;
fastcgi_no_cache $nocache;

所以,对于Do-Cache: public,nginx 应该缓存响应。否则不行。

但此配置不起作用。通过调试日志,$sent_http_do_cache$nocache 的值是正确的,直到它们用于 nginx 的服务器块。如果在服务器块中使用它们(fastcgi_cache_bypass $nocache,或简单的set $a $nocache),$nocache 变量得到“1”值,$sent_http_do_cache - “-”。

还有其他的方式来管理基于自定义响应头的nginx缓存吗?

【问题讨论】:

    标签: caching nginx


    【解决方案1】:

    无法进行基于响应头的缓存,因为这意味着 Nginx 必须将请求代理回后端并检查其响应,这违背了代理缓存的目的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-08
      • 1970-01-01
      • 2018-03-09
      • 1970-01-01
      • 1970-01-01
      • 2016-02-10
      • 2015-04-14
      • 2018-06-05
      相关资源
      最近更新 更多