有三台机器,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;
}