针对nginx做负载均衡时其中一台服务器挂掉宕机时响应速度慢的问题解决
nginx会根据预先设置的权重转发请求,若给某一台服务器转发请求时,达到默认超时时间未响应,则再向另一台服务器转发请求。
默认超时时间1分钟。修改默认超时时间为1s:
server { listen 80; server_name localhost; location / { proxy_pass http://Target_IP_or_Domain ; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_connect_timeout 1; proxy_read_timeout 1; proxy_send_timeout 1; } ... }
说明:其中使用了变量$host,$remote_addr等,这个的说明见:http://nginx.org/en/docs/http/ngx_http_core_module.html#variables 这里面由内嵌的各种变量以及变量说明