我想通过使用自定义 header :“Do-Cache”从我的脚本中实现自定义 nginx 缓存控制方法。 我在 nginx 的 http block 中使用:
map $sent_http_do_cache $nocache {
public 0;
default 1;
}
在 nginx 的服务器 block 中:
fastcgi_cache_bypass $nocache;
fastcgi_no_cache $nocache;
因此,对于 Do-Cache: public
,nginx 应该缓存响应。否则不会。
但是这个配置不起作用。通过调试日志,$sent_http_do_cache
和 $nocache
的值是正确的,直到它们被用于 nginx 的服务器 block 。如果在服务器 block 中使用它们(fastcgi_cache_bypass $nocache
,或一个简单的set $a $nocache
),$nocache
变量得到“1"值和 $sent_http_do_cache
- "-"。
是否有任何其他方法可以根据响应中的自定义 header 来管理 nginx 的缓存?
最佳答案
无法根据响应头进行缓存,因为这意味着 Nginx 必须将请求代理回后端并检查其响应,这违背了代理缓存的目的。
https://stackoverflow.com/questions/43241489/
相关文章:
python - 如何访问FormView中的request对象
php - SwiftMailer 在电子邮件正文中附加图像
sql - 为什么非聚集索引列仍然进行索引扫描而不是索引查找
angularjs - 如何将 gmail api 正确加载到 angular 2 应用程序
arduino - ESP8266 不断重启 rst cause :4, boot mode :(3
django - 是否有可能让预定的 celery 任务剩余几秒
javascript - 如何在 Chart.js 的条形图列中添加背景图片?