nginx負載均衡策略

目錄

 

1 默認輪詢

2 weight

3 ip_hash

4 fair

按後端服務器的響應時間來分配請求,響應時間短的優先分配。 


1 默認輪詢

2 weight

 upstream myserver {
        server 39.102.128.122:8081 weight=10;   #  這裏配置
        server 39.102.128.122:8082 weight=10;
    }
    server {
        listen       80;
        server_name  39.102.128.122;
        location / {
            root   html;
            proxy_pass   http://myserver;
            index  index.html index.htm;
    }

3 ip_hash

每個請求按訪問 ip 的 hash 結果分配,這樣每個訪客固定訪問一個後端服務器 

 

    upstream myserver {
    	ip_hash;							//  這裏配置
        server 39.102.128.122:8081 ;   
        server 39.102.128.122:8082 ;
    }
    server {
        listen       80;
        server_name  39.208.128.122;
        location / {
            root   html;
            proxy_pass   http://myserver;
            index  index.html index.htm;
    }

4 fair

按後端服務器的響應時間來分配請求,響應時間短的優先分配。 

  upstream myserver {					
        server 39.102.128.122:8081 ;   
        server 39.102.128.122:8082 ;
        fair; 														#  在這兒
    }
    server {
        listen       80;
        server_name  39.102.128.122;
        location / {
            root   html;
            proxy_pass   http://myserver;
            index  index.html index.htm;
    }

 

發佈了146 篇原創文章 · 獲贊 18 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章