【问题标题】:nginx use stale cache not workingnginx 使用过时的缓存不起作用
【发布时间】:2015-04-19 13:25:27
【问题描述】:

我正在尝试使用 proxy_cache_use_stale 错误;当目标返回 http 状态 500 内部错误时,让 nginx 提供缓存页面。 我有以下设置:

location /test {
                proxy_cache     maincache;
                proxy_cache_valid 200 10s;
                proxy_cache_use_stale error;
                proxy_pass      http://127.0.0.1:3000/test;
        }
 location /toggle {
                proxy_pass      http://127.0.0.1:3000/toggle;
}

Test 将返回当前时间和 Http 状态 200 或当前时间和 http 状态 500。如果我调用 /toggle,则 /test 返回的值将从 200 切换到 500。

我的期望是我应该能够向 /test 发送调用并获取当前时间。然后我应该能够发送对 /toggle 的调用,并且对 /test 的调用将返回函数首次调用的时间。正在发生的事情是,它将最后一次缓存保持 10 秒,然后发回当前时间,根本不使用缓存。

我了解设置 proxy_cache_valid 200 10s;当返回 500 以外的内容时,将阻止它刷新缓存,并在 10 秒后将新内容存储在缓存中并且没有错误消息 回来。

我在阅读文档后假设,旧缓存不会被自动清除,直到经过的时间等于为缓存设置的非活动标志。我没有为缓存设置非活动标志,所以我预计“proxy_cache_use_stale 错误”会阻止缓存刷新,直到 10 分钟过去(未定义非活动时的默认值),或者不再返回错误。我误解了文档的哪一部分?这应该如何正确完成?

我所指的 Nginx 文档是在此处找到的文档。 http://nginx.org/en/docs/http/ngx_http_proxy_module.html?&_ga=1.112574977.446076600.1424025436#proxy_cache

【问题讨论】:

  • 你应该使用“http_500”而不是“error”,见nginx.org/en/docs/http/…
  • 感谢您的快速回复,错过了文档的那部分!问题解决了。如果我要将您的回复标记为答案,我认为您需要将其发布为答案而不是评论。
  • 完成,提前致谢

标签: caching nginx


【解决方案1】:

您应该使用“http_500”而不是“错误”,请参阅http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream(proxy_cache_use_stale 使用与 proxy_next_upstream 相同的参数)

【讨论】:

    猜你喜欢
    • 2017-11-30
    • 1970-01-01
    • 1970-01-01
    • 2022-06-17
    • 2021-07-09
    • 2018-03-27
    • 2014-04-30
    • 2018-10-18
    • 2011-11-08
    相关资源
    最近更新 更多