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
/usr/local/nginx/sbin/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