CentOS 6.7 Configuration Nginx 1.8 Load Balancer

Source: Internet
Author: User
Tags vps

This tutorial uses vultr VPS build, ready for three VPs, one master two from

45.32. 90.100 slave1   45.32. 92.47 slave2   45.32. 89.205

1. Compile and install Nginx 1.8

Three full-load, and start Nginx


2. Modify master configuration file

Increase in HTTP segment:

    Upstream Backend {        45.32.  92.47;         45.32. 89.205 ;        }

In the location section of the server, add:

            Proxy_pass http://backend;

3, complete nginx.conf as follows:

#user nobody;worker_processes1; #error_log logs/Error.log, #error_log logs/error.log notice; #error_log logs/error.logInfo; #pid logs/nginx.pid;events {worker_connections1024x768;}    HTTP {include mime.types; Default_type Application/octet-stream; #log_format Main'$remote _addr-$remote _user [$time _local] "$request"'    #                  '$status $body _bytes_sent "$http _referer"'    #                  '"$http _user_agent" "$http _x_forwarded_for "'; #access_log logs/Access.log Main;    Sendfile on;    #tcp_nopush on; #keepalive_timeout0; Keepalive_timeout $; #gzipOn ; Upstream Backend {server45.32.92.47weight=2; Server45.32.89.205; } Server {Listen the;        server_name localhost; #charset Koi8-R; #access_log logs/Host.access.log Main; Location/{root HTML;            Index index.html index.htm; Proxy_pass http://backend;} #error_page404/404. html; # REDIRECT Server error pages to the static page/50x.html # Error_page - 502 503 504/50x.html; Location= /50x.html {root html; }    }}

4. Restart the Nginx on master

/usr/local/nginx/sbin/nginx-s Reload

5. Verification

To modify a Web page file in slave1

Echo " slave1 " >/usr/local/nginx/html/index.html

To modify a Web page file in Slave2

Echo " Slave2 " >/usr/local/nginx/html/index.html

Enter Master's IP in the browser and refresh the view to see alternate slave1 and Slave2

In addition, you can set weights

    Upstream Backend {        45.32.  92.47 weight=2;         45.32. 89.205 weight=1;        }

CentOS 6.7 Configuration Nginx 1.8 Load Balancer

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.