網站首頁 學習教育 IT科技 金融知識 旅遊規劃 生活小知識 家鄉美食 養生小知識 健身運動 美容百科 遊戲知識 綜合知識
當前位置:趣知科普吧 > IT科技 > 

nginx負載均衡配置

欄目: IT科技 / 發佈於: / 人氣:3.13W

產品型號: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;

     }

如圖中所示位置:

nginx負載均衡配置

添加反向代理,將訪問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服務進行測試負載均衡效果