gpt4 book ai didi

Nginx:在我的缓存中打一个洞没有按预期工作

转载 作者:行者123 更新时间:2023-12-05 05:17:12 24 4
gpt4 key购买 nike

我有一个单页应用程序,我正在尝试使用查询参数 nocahce=true 绕过 Nginx 缓存以获取第一个响应(HTML 文件)和它发起的所有后续请求(获取 CSS、JS 等)。

根据 this ,我可以使用查询参数绕过我的缓存,但它没有按预期工作。

重现问题的步骤:

使用这个缩小的通用配置:

http {
...
proxy_cache_path /var/temp/ levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g;
server {
...
location / {
# Using angularjs.org as an example
proxy_pass https://angularjs.org;
proxy_set_header Host angularjs.org;

proxy_cache STATIC;
proxy_cache_valid 200 10m;
proxy_cache_bypass $arg_nocache;
add_header X-Cache-Status $upstream_cache_status always;
}
}
}

预期:

请求“http://servername”和“http://servername/css/bootstrap”(或由http://servername?nocache=true发起的任何其他后续请求)绕过缓存的响应 header ,即包含“X-缓存状态:旁路”。

实际:

http://servername”的响应 header 包含“X-Cache-Status: BYPASS”,但“http://servername/css/bootstrap”不包含,“X-Cache-Status”的值是 HIT/MISS/etc,具体取决于缓存状态。

我是否以错误的方式使用了 proxy_cache_bypass,或者我是否需要做更多的事情来实现预期的行为?

谢谢!

最佳答案

我使用 cookie_nocache 解决了这个问题。

将指令 proxy_cache_bypass 更新为:

proxy_cache_bypass $cookie_nocache;

如果您需要绕过缓存,请将名为“nocache”的 cookie 设置为 true(任何非空或 0 的值都可以)。由于浏览器会将 cookie 发送到后续请求,因此这将起作用。

要快速测试它,请打开控制台并像这样添加 cookie。

document.cookie="nocache=true"

关于Nginx:在我的缓存中打一个洞没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49572488/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com