Nginx Load Balancer Reverse Proxy

Source: Internet
Author: User

A (master), B, C server, a primary server

Principle:

Domain name resolves to a server, a server is assigned to B, C server


Core configuration (The configuration method master does not provide services):

Upstream nginx.cn {

#ip_hash;

#server 192.168.1.228:80 weight=5;

#server 192.168.1.224:80 weight=5;

Server 192.168.1.228:80;

Server 192.168.1.240:80;

}

server{

Listen 80;

server_name nginx.cn;

Location/{

Proxy_pass http://nginx.cn;

if ($request _uri ~* ". *\. ( JS|CSS|GIF|JPG|JPEG|PNG|BMP|SWF) ($ ") {

Proxy_pass http://nginx.cn;

}

}

location/status{

Auth_basic "Nginxstatus";

Stub_status on;

Access_log on;

}

}


If the IP of the primary server is put into the upstream, the server will assign itself to load tasks, unlimited self-mobilization, will cause a dead loop.

because:Port 80 has been used to monitor the processing of load balancing, then the server can no longer use the 80 port to process access requests, you have to use a new. So we add the nginx.conf of the main server to the following code:

server{
Listen 8080;
server_name a.com;
Index index.html;
root/data0/htdocs/www;
}


All configurations (The configuration method master server does not provide services):

User www www;

Worker_processes 10;

PID Nginx.pid;

events{

Use Epoll;

Worker_connections 51200;

}

HTTP {

Include Mime.types;

Default_type Application/octet-stream;

Keepalive_timeout 120;

Tcp_nodelay on;

Upstream nginx.cn {

#ip_hash;

#server 192.168.1.228:80 weight=5;

#server 192.168.1.224:80 weight=5;

Server 192.168.1.228:80;

Server 192.168.1.240:80;

}

server{

Listen 80;

server_name nginx.cn;

Location/{

Proxy_pass http://nginx.cn;

if ($request _uri ~* ". *\. ( JS|CSS|GIF|JPG|JPEG|PNG|BMP|SWF) ($ ") {

Proxy_pass http://nginx.cn;

}

}

location/status{

Auth_basic "Nginxstatus";

Stub_status on;

Access_log on;

}

}

}


Other webserver only need to configure the appropriate domain name to



Nginx Load Balancer Reverse Proxy

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.