NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
zanelee
V2EX  ›  NGINX

注释了部分 upstream 的 server 后 Nginx 明明 reload 了但是访问依然会连接到原来的 server

  •  
  •   zanelee · Dec 28, 2023 · 2363 views
    This topic created in 888 days ago, the information mentioned may be changed or developed.

    有个系统后端 upstream 有 40 个节点,有些节点我们有健康检查并脚本注释并重新 reload 。但是发现 reload 后再次访问发现会出现 502 。然后我们自己手动测试发现随机注释几个节点,reload 后还会有请求到已经被注释的节点上。reload 肯定是成功的我保证。

    6 replies    2023-12-29 11:31:55 +08:00
    fredcc
        1
    fredcc  
       Dec 28, 2023
    nginx reload = SIGHUP signal
    changing configuration, keeping up with a changed time zone (only for FreeBSD and Linux), starting new worker processes with a new configuration, graceful shutdown of old worker processes
    具体看官网吧
    https://nginx.org/en/docs/control.html
    yinmin
        2
    yinmin  
       Dec 28, 2023 via iPhone   ❤️ 1
    nginx -s reload 不会重置已有的 http/https 链接。由于浏览器会重用 http/https 链接,因此你 reload 配置后刷新网站->浏览器重用老的链接->nginx 使用老配置;如果 reload 配置后重启浏览器访问就正常。

    解决方法是使用 force-reload 的命令:
    service nginx force-reload

    force-reload 有个缺点,用户正在下载文件会被强制中断。
    yinmin
        3
    yinmin  
       Dec 28, 2023 via iPhone
    nginx 官方解决方法是使用健康度检查命令 health_check ,是 nginx plus 的功能。也有第三方插件能实现类似功能。
    yinmin
        4
    yinmin  
       Dec 28, 2023 via iPhone
    upstream 节点的健康度处理,不推荐改配置然后 reload 。建议用 nginx 的健康度检测功能或 nginx 第三方健康度检测插件
    zanelee
        5
    zanelee  
    OP
       Dec 29, 2023
    @yinmin 浏览器重用老的 http 链接我知道,可是 reload 之后不是会等待断开老 worker 的所有连接,启动新配置的 worker 。浏览器刷新的时候不是应该会到新 worker 的新配置
    salmon5
        6
    salmon5  
       Dec 29, 2023
    proxy_pass 用默认的短连接试试看,
    注释掉:
    #proxy_http_version 1.1;
    #proxy_set_header Connection "";
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1188 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 17:44 · PVG 01:44 · LAX 10:44 · JFK 13:44
    ♥ Do have faith in what you're doing.