Nginx 3 virtual Machine load Balancing in the CentOS environment

Source: Internet
Author: User

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

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.