搭建一個簡單的負載均衡,然后關閉其中一臺再來訪問,會發(fā)現(xiàn)我們的瀏覽器卡住一直轉圈圈,過了很久才會顯示結果。由此我們可以得出結論Nginx負載的時候如果其中一臺服務掛掉了,它會把請求轉發(fā)到另一個可以提供服務的機器,其中這之間的超時等待默認是60s。我們可以通過這一個配置去改變這個時間,proxy_connect_timeout
定義與代理服務器建立連接的超時。
請注意,此超時通常不能超過75秒。文章來源:http://www.zghlxwxcb.cn/news/detail-718216.html
upstream cluster{
server nacos-node1.strongman.cluster.local:8848;
server nacos-node2.strongman.cluster.local:8848;
server nacos-node3.strongman.cluster.local:8848;
server nacos-node4.strongman.cluster.local:8848;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://cluster;
proxy_set_header Host $http_host;
# 添加 HTTP 響應頭,以便知道負載到哪臺服務器上
add_header backendIP $upstream_addr;
# 響應碼
add_header backendCode $upstream_status;
# 服務器與被代理服務連接超時時間,代理超時
proxy_connect_timeout 60s;
}
}
參考配置
Module ngx_http_proxy_module文章來源地址http://www.zghlxwxcb.cn/news/detail-718216.html
到了這里,關于【Nginx】負載均衡當其中一臺服務器宕機之后的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!