Nginx入門之負載均衡配置

2021-08-22 04:33:57 字數 1270 閱讀 4263

nginx負載均衡一些基礎知識:

nginx 的 upstream目前支援 4 種方式的分配

1)、輪詢(預設) 

每個請求按時間順序逐一分配到不同的後端伺服器,如果後端伺服器down掉,能自動剔除。 

2)、weight 

指定輪詢機率,weight和訪問比率成正比,用於後端伺服器效能不均的情況。 

2)、ip_hash 

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

3)、fair(第三方) 

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

4)、url_hash(第三方)

配置步驟

1開啟nginx.conf檔案

2配置upstream模組

在http{}內新增

upstream  webservice   

3配置訪問服務

server

}

這裡不知道什麼原因 只有配置在80埠是才可以實現,等研究出問題了在更新。。。

4配置模組對應的專案

server 

}#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#error_page 500 502 503 504 /50x.html;

location = /50x.html

# proxy the php scripts to apache listening on 127.0.0.1:80

##location ~ \.php$

# pass the php scripts to fastcgi server listening on 127.0.0.1:9000

#location ~ \.php(.*)$

# deny access to .htaccess files, if apache's document root

# concurs with nginx's one

##location ~ /\.ht

}

5動態圖

Nginx之負載均衡配置(二)

前文我們聊到了nginx作為負載均衡的配置,前端nginx作為排程器排程http或https請求,回顧請參考其實nginx面向客戶端一側它除了可以 http或https的請求外,它還可以 tcp的請求,因為nginx它本身工作在應用層,通常情況下我們把它 tcp的請求叫做偽四層排程 在之前的文章中我...

Nginx之負載均衡配置(一)

前文我們聊了下nginx作為反向 伺服器,後端動態應用伺服器的配置,回顧請參考今天我們來聊一聊nginx作為反向 伺服器,一組伺服器的配置 負載均衡 前邊我們只說到了nginx怎麼去 後端伺服器響應客戶端的請求,它在響應客戶端請求的流程是這樣的,使用者請求傳送到nginx 伺服器上,此時nginx伺...

nginx負載均衡配置

curl nginx upstream fair.zip unzip nginx upstream fair.zip cd nginx 1.6.2 檢視當前nginx 編譯引數 nginx v 輸出 configure arguments prefix usr local nginx configu...