Nginx 負載均衡

2021-08-21 16:30:12 字數 1435 閱讀 4354

> sudo apt-get update

> sudo apt-get install nginx

安裝完成後,配置檔案預設路徑:

/etc/nginx

我們在/etc/nginx/nginx.conf中的http模組可以看到:

##

# virtual host configs

##

include /etc/nginx/conf.d/*.conf;

include /etc/nginx/sites-enabled/*;

所以我們可以在conf.d資料夾下面建立反向**檔案:

> sudo touch proxy_172.conf

> sudo vim proxy_172.conf

寫入如下配置:

server

access_log /var/log/nginx/proxy_172.log;

}

重啟伺服器:

> sudo service nginx restart
現在你訪問反向**伺服器的8081埠,就會指向192.168.71.172伺服器的80埠。

->
如果你的web伺服器有多個(192.168.71.172:80和192.168.71.173:80),則可以使用負載均衡給伺服器減少壓力。

> cd /etc/nginx/conf.d

> sudo touch proxy_172_173.conf

> sudo vim proxy_172_173.conf

寫入如下配置:

upstream web_server

server

access_log /var/log/nginx/proxy_172_173.log;

}

現在訪問負載均衡伺服器的8082埠會隨機跳轉到2個web伺服器上:

-> 192.168.71.172:80

-> 192.168.71.173:80

nginx 負載均衡 Nginx負載均衡策略

nginx提供的負載均衡策略有2種 內建策略和擴充套件策略。內建策略為輪詢 預設 加權輪詢,ip hash,第三方。upstream mysvr1 輪詢 每個請求按照時間順序逐一的分配到每乙個後台伺服器上。如果某台伺服器宕機了,將會自動的剔除宕機的服務。nginx預設就是輪詢其權重都預設為1,伺服器...

nginx負載均衡

nginx 的 upstream目前支援 4 種方式的分配 1 輪詢 預設 每個請求按時間順序逐一分配到不同的後端伺服器,如果後端伺服器down掉,能自動剔除。2 weight 指定輪詢機率,weight和訪問比率成正比,用於後端伺服器效能不均的情況。3 ip hash 每個請求按訪問ip的hash...

nginx負載均衡

nginx s stop quick exit nginx s quit graceful quit nginx s reload changing configuration,starting a new worker,quitting an old worker gracefully nginx...