nginx 負載均衡

框架結構

192.168.178.131 負載均衡

192.168.178.130  web01

192.168.178.129  web02


3臺服務器上都安裝相同的nginx版本

192.168.178.131 的配置加入

upstream test.miaohr.com {     ——————####### test.miaohr.com這個必須和下面的 proxy_pass 一致 下面是weight模式負載

    server 192.168.178.129:80 weight=80;

    server 192.168.178.130:80   weight=10;

      }

 server {

             listen 80;

    server_name test.miaohr.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;


        location / {

              root   html;

            index  index.html index.htm;

            proxy_pass        http://test.miaohr.com;

            proxy_set_header  X-Real-IP  $remote_addr;

            client_max_body_size  100m;

        }




192.168.178.130  web01和web02 只需要配置域名主機就可以了

 server {

        listen       80;

        server_name  test.miaohr.com;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;


        location / {

            root   html;

            index  index.html index.htm;

        }




1,加權負載模式

   ——————####### test.miaohr.com這個必須和下面的 proxy_pass 一致 下面是weight模式負載

    upstream test.miaohr.com {   

    server 192.168.178.129:80 weight=80;  weight 爲後臺服務器的訪問機率的百分比

    server 192.168.178.130:80   weight=10;

      }

2輪詢模式

   ——————####### test.miaohr.com這個必須和下面的 proxy_pass 一致 下面是輪詢 會1:1的去訪問後端服務器

upstream test.miaohr.com {   

    server 192.168.178.129:80;

    server 192.168.178.130:80;

      }



3、ip_hash
每個請求按訪問ip的hash結果分配,這樣每個訪客固定訪問一個後端服務器,可以解決session的問題。

upstream test.miaohr.com {     ——————####### test.miaohr.com這個必須和下面的 proxy_pass 一致 下面是輪詢 會1:1的去訪問後端服務器

upstream test.miaohr.com {  

        ip_hash; 

    server 192.168.178.129:80;

    server 192.168.178.130:80;

      }


測試 綁定vhost 負載均衡ip 192.168.178.131 test.miaohr.com

在web01和web02下 test.miaohr.com 目錄同時建一個test.html的文件不同內容

訪問test.miaohr.com/test.html 頁面頁面信息不一樣

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章