记录NGINX负载重试的可用性问题

本文介绍了在NGINX中配置负载均衡时遇到的问题,即后端服务返回500状态码时,负载均衡器未能按预期切换到其他服务器。通过分析,发现默认情况下,非幂等请求(如POST)不会被重试。解决方案是在`proxy_next_upstream`指令中添加`error timeout http_500 non_idempotent`参数,允许重试包括500错误在内的请求,确保在高版本NGINX中实现服务器间的负载切换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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的,负载到下一台的效果

NGINX的proxy_next_upstream文档资料


原因分析:

我也不知道啥原因,


解决方案:

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就可以了,目前是高版本支持。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值