默认nginx会开启 健康检查,如果简单写成

    server 192.168.1.2:80;

    server 192.168.1.3:80;

    默认权重为1,max_fails 为1 fail_timeout=10s

    所以如果需要关闭默认的健康检查需要将max_fails设置为0,表示禁用默认的健康检查

    如果使用第三方健康检查模块,必须将默认的健康检查关闭,如使用nginx_upstream_check_module模块,配置样例:

       check interval=3000 rise=2 fall=2 timeout=1000 type=http;

       check_keepalive_requests 100;

       check_http_send "HEAD /health HTTP/1.1\r\nHost: www.centosdoc.com\r\nConnection: keep-alive\r\n\r\n";

       check_http_expect_alive http_2xx http_3xx;

    

    多个location共用一个upstream其中一个location大量报错会导致nginx判断当前共用upstream源站,从而影响其他location对源站的访问,所以nginx要避免多个location共用一个upstream

案例一:

当前配置如下:

upstream f471999614347f181d0a01c88ce778d6 {     # md5("www.centosdoc.com"+"/")

  zone zone_for_f471999614347f181d0a01c88ce778d6 1M;

   server 192.168.1.2:80 weight=10 max_fails=3 fail_timeout=6s;

   server 192.168.1.3:80 weight=10 max_fails=3 fail_timeout=6s;

   check interval=3000 rise=2 fall=2 timeout=1000 type=http;

   check_keepalive_requests 100;

   check_http_send "HEAD /health HTTP/1.1\r\nHost: www.centosdoc.com\r\nConnection: keep-alive\r\n\r\n";

   check_http_expect_alive http_2xx http_3xx;

}

upstream notifications_v2 {     # md5("www.centosdoc.com"+"/")

  zone zone_for_notifications_v2 1M;

   server 192.168.1.2:80 weight=10 max_fails=3 fail_timeout=6s;

   server 192.168.1.3:80 weight=10 max_fails=3 fail_timeout=6s;

}

server {

  server_name www.centosdoc.com;

  listen 80;

  index index.aspx index.shtml index.html;

  access_log /data/nginx/logs/www.centosdoc.com_access.log access;

  keepalive_timeout 65;

  location / {

proxy_pass http://f471999614347f181d0a01c88ce778d6;

  }

}

只有两个url地址提供服务,/notifications/v2和/services/config 其中/notifications/v2大量报504导致默认nginx检测认为源站没有存活主机 ,从而导致/services/config 部分报502错误

以上有两种解决

1、将/notifications/v2地址单独拆分出来一个location和upstream,从而避免误伤

2、更换探活模块,并且将默认探活禁用

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注