Nginx implements detailed configuration of Cluster load balancing, nginx Load Balancing

Source: Internet
Author: User
Tags nginx server nginx load balancing

Nginx implements detailed configuration of Cluster load balancing, nginx Load Balancing

In fact, the Nginx Server Load balancer function is the same as the nginx proxy function. Instead, you only need to change one proxy machine to multiple servers. Compared with lvs, Nginx is a more advanced application layer. It simply forwards user requests to the following machines without any changes to the ip address and kernel. This means that the backend RS does not need to be configured with a public network.

I. experiment environment

Nginx scheduler (public 172.16.254.200 privite 192.168.0.48)
RS1 only has an intranet IP address (192.168.0.18)
RS2 only has an Internet IP address (192.168.0.28)

 

Ii. Configuration File

Edit the configuration file on the nginx Scheduler

# vim /usr/local/nginx/conf/vhosts/lb.conf

Add the following content:

upstream test {    ip_hash;    server 192.168.0.18;    server 192.168.0.28;}server {    listen 80;150    server_name www.aminglinux.com;    location / {        proxy_pass http://test/;        proxy_set_header Host $host;        proxy_set_header X-Real-IP $remote_addr;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    } }

 

Iii. configuration instructions

You will find that this configuration is exactly the same as the nginx proxy configuration we mentioned earlier, but an upstream is added. This upstream is used to define the backend RS and can only write one. Ip_hash is a scheduling algorithm of nginx. After this line is added, a user's request is evenly distributed to a fixed RS. This helps avoid session loss when requests from the same user are distributed to different machines. In upstream, you can add weights to the ip address after RS, for example, "server 192.168.31.100 weight = 100 ;". Note that test after upstream is a user-defined name and can be written at will. The only requirement is to be consistent with that after proxy_pass.

 

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.