Nginx-Based load balancing

Source: Internet
Author: User

1. Scene

Nginx3 connecting the WAN to other servers inside the network

Nginx 1---------------------

/      \      \                              \

Server 1 server 2 Server3 nginx3 <--

\       /      /                              /

Nginx 2-----------------------

2. Ideas

NGINX3 for ingress reverse proxy, load balancer to NGINX1, 2

Nginx 1, 2 reverse proxy and load balancer Servier1, 2, 3

3. Configuration files

NGINX3 configuration:

Upstream lb.tin.com {
Server 10.221.148.167:80; #nginx1
Server 10.251.216.232:80; #nginx2
}

Upstream pro1.tin.com {

Server 10.221.148.167:80;
}

Upstream pro2.tin.com {
Server 10.251.216.232:80;
}

server {
Listen 80;
server_name loalhost;
Location/pro1 {
Proxy_pass http://pro1.tin.com;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}
Location/pro2 {
Proxy_pass http://pro2.tin.com;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}

}

NGINX1, 2 configuration:

NGINX1 Example:

Upstream pro1.tin.com {
Server 10.221.148.160:8080; #server1
Server 10.251.216.230:8080; #server2

Server 10.251.216.231:8080; #server3

}

Upstream server1.tin.com {

Server 10.221.148.160:8080;
}

Upstream server2.tin.com {
Server 10.251.216.230:8080;
}

Upstream server3.tin.com {
Server 10.251.216.231:8080;
}

server {
Listen 8080;
server_name loalhost;
Location/server1 {
Proxy_pass http://server1.tin.com;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}
Location/server2 {
Proxy_pass http://server2.tin.com;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}

Location/server3 {
Proxy_pass http://server3.tin.com;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}

}

Nginx-based load balancing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.