There are three machines, ABC,
All requests are sent to A, and then A forwards it to BC, and BC handles the business
Assume that the domain name is bla.com
on machine A , write the following configuration in the http module, access bla.com
, and access the A default page
upstream bla.com {
ip_hash;
server 192.168.100.2;
server 192.168.100.3;
}
How can all requests be forwarded to B and C according to
ip_hash
phpcn_u15822017-05-16 17:16:02
https load balancing architecture is as shown in the figure, which is not much different from 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
You mean, you don’t want server A to bear the traffic?
When server A forwards to the backend, set a special header
add_header HELLO Y;
When B and C find the HELLO header, they immediately return 302, allowing the user to directly initiate a connection to B and C
if ($http_HELLO = 'Y'){
rewrite ^ http://$server_addr:$server_port$request_uri? redirect;
}