nginx 负载平衡不会忽略非工作 IP

nginx 负载平衡不会忽略非工作 IP

我是 nginx 新手,我遇到了这个我无法理解的问题。

我正在使用 nginx 作为三个云服务器的负载均衡器。这是 nginx 配置:

upstream dummyname  {
      server #.#.#.# weight=1;
      server #.#.#.# weight=1;
      server #.#.#.# weight=1;
    }

server {
listen 80;
root /var/www/html;
try_files /maintenance.html $uri $uri/index.html $uri.html @proxy;
server_name localhost;
location @proxy {
proxy_pass  http://dummyname;
}
}

我的问题出现了,当我销毁其中一个时,它的 ip 仍然在上游,我开始收到此错误:

ERROR
The requested URL could not be retrieved

The following error was encountered while trying to retrieve the URL: http://dummyname

Unable to determine IP address from host name "dummyname"

The DNS server returned:

Name Error: The domain name does not exist.

This means that the cache was not able to resolve the hostname presented in the URL. Check if the address is correct.

Your cache administrator is webmaster.

追踪该错误后,我发现问题出在已删除服务器的 IP 上,如果我从上游删除该 IP,它就可以正常工作。

现在 nginx 不是应该平衡负载并忽略任​​何不工作的 ip 吗?或者这是正常的,或者我做错了什么?任何参考资料都非常感谢。

提前致谢。

答案1

您应该在上游块中提高 fail_timeout 值,这样失败的服务器将不再被标记为失败。

(引自 nginx 文档,粗体部分是我加的)来自http://nginx.org/en/docs/http/ngx_http_upstream_module.html

fail_timeout=time 设置在指定时间内与服务器通信的尝试失败次数达到指定次数时,将认为服务器不可用;以及服务器将被视为不可用的时间段。默认情况下,该参数设置为10秒。

相关内容