Implement nginx load balancing and reverse proxy in centos

Source: Internet
Author: User
Tags nginx load balancing

1. install necessary software

Server Load balancer: set IP address to 192.168.1.10

Web Server 1: install Apache or nginx and set the IP address to 192.168.1.11;

Web Server 2: install Apache or nginx and set the IP address to 192.168.1.12.

Ii. Configure the server Load balancer instance

1. Create an extra folder under the nginx conf directory and edit and generate a configuration file, such as t_servers.conf.

Upstream test_servers {

Server 192.168.1.11: 80 Weight = 5;
Server 192.168.1.12: 80 Weight = 5;
}
Server {
Listen 80;
SERVER_NAME 192.168.1.10;
Location /{
Proxy_pass http: // test_servers;
}
}

2. Edit the nginx. conf file under the nginx conf directory, and only keep the necessary configurations below, and save the configuration files under the last line include.

 

Worker_processes 1;

Events {

Worker_connections 1024;
}

HTTP {
Include mime. types;
Default_type application/octet-stream;

Sendfile on;

Keepalive_timeout 65;

Include extra/t_servers.conf;
}

3. Restart the nginx Server

Each access to 192.168.1.10 will automatically switch between Web Server 1 and Server 2 to achieve load balancing and reverse proxy. If one of the Web servers goes down, the access will automatically jump to the working web server. If nginx is down, error 502 is returned.

Related Article

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.