NGINX负载配置max_fails和fail_timeout使用问题:
总体配置的情况如下:
server {
listen 8090;
server_name localhost:8090;
location / {
proxy_pass http://springboot;
proxy_read_timeout 30;
}
}
upstream springboot {
server localhost:8080 max_fails=1 fail_timeout=60s;
server localhost:8081 max_fails=1 fail_timeout=60s;
server localhost:8082 max_fails=1 fail_timeout=60s;
}
问题描述:
当前是服务服务返回的状态码是:500,那我们就需要增加判断哪些情况下是失效的:因此增加:
proxy_next_upstream error timeout http_500
不生效,目前后端返回500的状态,不能完成max_fails的,负载到下一台的效果
原因分析:
我也不知道啥原因,
解决方案:
non_idempotent normally, requests with a non-idempotent method (POST, LOCK, PATCH) are not passed to the next server if a request has been sent to an upstream server (1.9.13); enabling this option explicitly allows retrying such requests;
proxy_next_upstream error timeout http_500 non_idempotent
增加了non_idempotent就可以了,目前是高版本支持。
本文介绍了在NGINX中配置负载均衡时遇到的问题,即后端服务返回500状态码时,负载均衡器未能按预期切换到其他服务器。通过分析,发现默认情况下,非幂等请求(如POST)不会被重试。解决方案是在`proxy_next_upstream`指令中添加`error timeout http_500 non_idempotent`参数,允许重试包括500错误在内的请求,确保在高版本NGINX中实现服务器间的负载切换。
3569

被折叠的 条评论
为什么被折叠?



