Server - nginx how to configure load balancing
怪我咯
怪我咯 2017-05-16 17:14:02
0
2
417

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

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
phpcn_u1582

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;
    }
}
左手右手慢动作

You mean, you don’t want server A to bear the traffic?

  1. When server A forwards to the backend, set a special header

add_header HELLO Y;
  1. 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;
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!