Nginx proxy_cache缓存502错误 [英] Nginx proxy_cache caches 502 errors

查看:355
本文介绍了Nginx proxy_cache缓存502错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Nginx proxy_cache来缓存来自节点服务器的响应.当该服务器离线时,Nginx返回一个自定义的502页面.到目前为止一切顺利...

I'm using Nginx proxy_cache to cache responses from a Node server. When that server is offline Nginx returns a custom 502 page. All going well so far...

当节点服务器重新联机时,Nginx持续返回502页面达5分钟(我的缓存时间).如果删除缓存目录中的所有文件,则没有任何区别.如果我重新启动Nginx,它将破坏缓存并再次开始提供真实内容.

When the Node server comes back online Nginx keeps returning the 502 page for 5 mins (my cache time). If I delete all the files in the cache dir it makes no difference. If I restart Nginx it busts the cache and starts serving real content again.

Nginx缓存502s是否正常?请注意,它不是在缓存来自后端服务器的502响应,而是在缓存该服务器不可访问的事实.

Is it normal for Nginx to cache 502s? Note that it's not caching a 502 response from the backend server it's caching the fact that the server isn't accessible.

我该怎么做才能阻止这种情况?

What can I do to stop this?

推荐答案

我自己弄清楚了这一点. Nginx实际上确实缓存了上游服务器不可访问的知识.

I managed to figure this out myself. Nginx really does cache the knowledge that the upstream server is inaccessible.

要解决此问题,我将缓存配置从proxy_cache_valid any 5m;更改为proxy_cache_valid 5m;删除any意味着您只想缓存200、301和302响应.

To fix this I changed my cache config from proxy_cache_valid any 5m; to proxy_cache_valid 5m; Removing any implies you only want to cache 200, 301, and 302 responses.

这篇关于Nginx proxy_cache缓存502错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆