有三台機器,ABC,
所有請求都給A,然後A轉發給BC,由BC處理業務
假設域名是bla.com
在機器A上,http 模組內寫以下配置,訪問bla.com
,訪問到的是A預設頁面
upstream bla.com {
ip_hash;
server 192.168.100.2;
server 192.168.100.3;
}
怎麼樣才能讓所有的請求都按 ip_hash
轉發給B,C
phpcn_u15822017-05-16 17:16:02
https 負載平衡架構如圖,與http差異不大
upstream mywebapp1 {
server 10.130.227.11;
server 10.130.227.22;
}
server {
listen 80;
listen 443 ssl;
server_name example.com www.example.com;
ssl on;
ssl_certificate /etc/nginx/ssl/example.com/server.crt;
ssl_certificate_key /etc/nginx/ssl/example.com/server.key;
ssl_trusted_certificate /etc/nginx/ssl/example.com/ca-certs.pem;
location / {
proxy_pass http://mywebapp1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
ringa_lee2017-05-16 17:16:02
你的意思是, 不想讓A伺服器承擔流量了?
在伺服器A轉發給後端時, 設定特殊的header
add_header HELLO Y;
B,C在發現有HELLO這個header時,立即返回302,讓用戶對B,C直接發起連線
if ($http_HELLO = 'Y'){
rewrite ^ http://$server_addr:$server_port$request_uri? redirect;
}