我正在尝试演示nginx的负载平衡功能。我的nginx配置如下
.
.
upstream myapp1 {
server 127.0.0.1:3001 max_fails=1 fail_timeout=60s;
server 127.0.0.1:3002 max_fails=1 fail_timeout=60s;
server 127.0.0.1:3003 max_fails=1 fail_timeout=60s;
}
然后在服务器部分
.
.
location /myapp1 {
proxy_pass http://myapp1;
proxy_connect_timeout 10s;
}
.
.
使用此配置,Nginx确实以循环方式从所有三台服务器提供数据。但是当其中一台服务器被关闭时,例如一个监听3003的设备,即使收到来自它的连接超时,nginx仍然尝试重复连接它。唯一的问题是,它需要60秒,然后才从一台活动服务器中提供数据。
这是error.log文件的内容(这很有意义,但仅在客户端尝试连接60秒后才会显示)
2018/09/02 21:54:28 [error] 12704#6588: *865 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /myapp1 HTTP/1.1", upstream: "http://[::1]:3003/myapp1", host: "localhost"
我尝试在http,服务器和位置部分中为proxy_connect_timeout设置不同的值,但是这种行为不会改变。
如何使nginx表现为以下方式
nginx 1.15.3版。