nginx負載均衡配置
- IT科技
- 關注:3.11W次
產品型號:Thinkpad E15
系統版本:centos8
安裝nginx服務
[root@xuegod63 ~]# yum install -y epel-release
[root@xuegod63 ~]# yum install -y nginx
[root@xuegod63 ~]# vim /etc/nginx/nginx.conf
在server欄位外新增配置
upstream htmlservers {
server 192.168.1.62:80;
server 192.168.1.64:80;
}
如圖中所示位置:
新增反向代理,將訪問192.168.1.63的資料,轉到另外兩臺伺服器上
改:
51 location / {
52 }
為:
location / {
proxy_pass http://htmlservers;
}
檢查語法
[root@xuegod63 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
配置xuegod62和xuegod64節點
[root@xuegod62 ~]# yum install -y httpd
[root@xuegod62 ~]# echo "192.168.1.62" > /var/www/html/index.html
[root@xuegod62 ~]# systemctl start httpd
[root@xuegod64 ~]# yum install -y httpd
[root@xuegod64 ~]# echo "192.168.1.64" > /var/www/html/index.html
[root@xuegod64 ~]# systemctl start httpd
訪問web服務:http://192.168.1.63/
重新整理頁面即可看到主機頁面。
總結:
1. 安裝nginx服務
2. 配置nginx負載均衡
3. 啟動伺服器
4. 通過訪問web服務進行測試負載均衡效果
- 文章版權屬於文章作者所有,轉載請註明 https://shqsg.com/dianzi/m214n.html