關閉→
當前位置:知科普>IT科技>nginx負載均衡配置

nginx負載均衡配置

知科普 人氣:3.04W

產品型號: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服務進行測試負載均衡效果

TAG標籤:#配置 #nginx #均衡 #負載 #