Tutorial on configuring Nginx Reverse proxy server load balancer in centos

Source: Internet
Author: User

Preparation:

Proxy-Server: 1.1.1.22 (Server load balancer)
Nginx-Server23: 1.1.1.23 (web23)
Nginx-Server24: 1.1.1.24 (web24)

Environment version:

Linux Nginx-Proxy 2.6.32-358. el6.x86 _ 64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

①: Nginx is installed and configured.

WEB server pre-configuration:

[Root @ Nginx-Server23 ~] # Echo "1.1.1.23-server23">/usr/local/nginx/html/index.html
[Root @ Nging-Server24 ~] # Echo "1.1.1.24-server24">/usr/local/nginx/html/index.html

Server load balancer configuration:

[Root @ Nginx-Proxy conf] # egrep-v "# | ^ $"/usr/local/nginx/conf/nginx. conf
Worker_processes 1;
Events {
Worker_connections 1024;
}
Http {
Include mime. types;
Default_type application/octet-stream;
Sendfile on;
Keepalive_timeout 65;
Upstream www.111cn.net {
Server 1.1.1.23: 80 weight = 20; # The weight value determines the Allocation Value. The server load balancer accesses 1.1.1.23 twice and 1.1.1.24 once.
Server 1.1.1.24: 80 weight = 10;
    }
Server {
Listen 80;
Server_name www.111cn.net;
Location /{
Proxy_pass http://www.111cn.net;
        }
Error_page 500 502 503 x.html;
Location =/50x.html {
Root html;
        }
    }
}

Note: server 1.1.1.23: 80 weight = 20; equivalent to server 1.1.1.23: 80 weight = 20 max_fails = 1 fail_timeout = 10 s;

Test:

[Root @ Nginx-Proxy conf] # curl 1.1.1.22
1.1.1.23-server23
[Root @ Nginx-Proxy conf] # curl 1.1.1.22
1.1.1.23-server23
[Root @ Nginx-Proxy conf] # curl 1.1.1.22
1.1.1.24-server24
[Root @ Nginx-Proxy conf] # curl 1.1.1.22
1.1.1.23-server23
[Root @ Nginx-Proxy conf] # curl 1.1.1.22
1.1.1.23-server23
[Root @ Nginx-Proxy conf] # curl 1.1.1.22
1.1.1.24-server24


Note: When one of the webservers goes down, it takes about 10 seconds for the server to be removed.

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.