【发布时间】: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缓存吗?
【问题讨论】: