关于 nginx 中 proxy_next_upstream 与 max_fails 之间的关系,求解

2021-02-26 09:47:22 +08:00
 jarry118

我理解的:upstream 中 max_fails 对应的 fail 类型,是由参数 proxy_next_upstream error 来定义的,比如 proxy_next_upstream error timeout http_500 http_502 http_503 http_504; 表示定义了超时、500 、502 、503 、504 请求为 fail 状态。

第一种场景:

proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
proxy_next_upstream_tries 3;

upstream test {
        server ip1:8080 weight=10 max_fails=2 fail_timeout=30s;
        server ip2:8080 weight=10 max_fails=2 fail_timeout=30s; 
        keepalive 200;
}

表示后台 server 在 30s 内如果失败两次(fail 类型包括超时、500 、502 、503 、504 请求),会重试 3 次请求这个后台 server,如果 3 次还是失败,则将这个 server 节点 down,请求到其他的 server 节点。

第二种场景:

proxy_next_upstream off;
proxy_next_upstream_tries 3;

upstream test {
        server ip1:8080 weight=10 max_fails=2 fail_timeout=30s;
        server ip2:8080 weight=10 max_fails=2 fail_timeout=30s; 
        keepalive 200;
}

此时 max_fails 不生效,server 发生问题时,该 server 后续还是会继续收到请求。

这里有个问题,如果设置为 proxy_next_upstream error,会发现第二种场景的情况吗?

1671 次点击
所在节点    NGINX
3 条回复
Judoon
2021-02-26 11:46:27 +08:00
取决于 "server 发生问题",是具体什么问题吧,根据文档 http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream
Judoon
2021-02-26 11:48:05 +08:00
error 表示建立连接失败,或者连接后收不到响应等,是协议连接层面的问题。
如果你的 server 给了个 500,那 nginx 就不会认为 server 是 down 的状态,当然继续发送
jarry118
2021-02-26 12:26:28 +08:00
@Judoon 感谢,学习了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/756384

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX