V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
jarry118
V2EX  ›  NGINX

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

  •  
  •   jarry118 · 2021-02-26 09:47:22 +08:00 · 1620 次点击
    这是一个创建于 1126 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我理解的: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,会发现第二种场景的情况吗?

    3 条回复    2021-02-26 12:26:28 +08:00
    Judoon
        1
    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
        2
    Judoon  
       2021-02-26 11:48:05 +08:00
    error 表示建立连接失败,或者连接后收不到响应等,是协议连接层面的问题。
    如果你的 server 给了个 500,那 nginx 就不会认为 server 是 down 的状态,当然继续发送
    jarry118
        3
    jarry118  
    OP
       2021-02-26 12:26:28 +08:00
    @Judoon 感谢,学习了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2933 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 15:09 · PVG 23:09 · LAX 08:09 · JFK 11:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.