Load Balancing
Let's start with a quick look at what is load balancing, which is interpreted literally to explain the average load sharing of n servers, not because a server is under-loaded and idle on a single server. Then the premise of load balancing is to have more than one server to achieve, that is, more than two units can be.
Test environment
Three CentOS installations are installed in VMware.
A server ip:192.168.0.219 (master)
b Server ip:192.168.0.119
C Server ip:192.168.0.109
Deployment Ideas
A server as the primary server, the domain name directly resolves to a server (192.168.0.219), by a server load balancer to B server (192.168.0.119) and C server (192.168.0.109).
On a server, upstream instructions--assigning loads
Vi/etc/nginx/conf.d/default.conf
Upstream 192.168.0.219 {
server 192.168.0.119:80;
server 192.168.0.109:80;
}
server {
listen ;
server_name 192.168.0.219;
CharSet UTF8;
location/{
proxy_pass http://192.168.0.219;
proxy_set_header host $host;
proxy_set_header x-real-ip $remote _addr;
proxy_set_header x-forwarded-for $proxy _add_x_ Forwarded_for;
}
}
Save Restart Nginx
On the B and C servers,
Vi/etc/nginx/conf.d/default.conf
server {
Listen 80;
server_name 192.168.0.219;
Index index.html;
root/usr/share/nginx/html;
}
Save Restart Nginx
Test
When accessing http://192.168.0.219, in order to distinguish between which server to handle I write a different content under the B, C server index.html file, to make a distinction.
Open the browser to access the A.com results, the refresh will find all the requests are allocated to the host server (192.168.5.149) on the B server (192.168.0.119) and C server (192.168.0.109), the load balancing effect.
This article is from the "Guangzhou Linux operation and Maintenance" blog, please be sure to keep this source http://milenovo.blog.51cto.com/10554394/1707238
Nginx 3 virtual Machine load Balancing in the CentOS environment