目錄
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;
}