Nginx Load balancer (based on ip/port)

Source: Internet
Author: User
Tags nginx load balancing

Schematic diagram of Nginx load balancing:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7F/E0/wKiom1cwXU-BvFj9AACDm7MqUAQ203.png "title=" 6xwxzuk%z~d_]1d[h7jj5t.png "alt=" Wkiom1cwxu-bvfj9aacdm7mquaq203.png "/>

Site content is deployed on apache1 and apache2, load balancing on Nginx, when users want to access apache1 and apache2 the content on the server, only need to access the Nginx server, Nginx will forward the request to the Web server apache1 and apache2, the Web server after processing the request, the content of the request sent to Nginx, Nginx then return the content to the user there.

This forwarding process, for the user is not feel, can not only protect the Web server security, but also improve the performance of the Web server.

How to set Load balancing:

, there is an Nginx server (192.168.1.100) and two Web servers (192.168.1.101/192.168.1.102)

Modify the contents of the home page file on two Apache servers, respectively:

This is A.

This is B.

Simply modify the configuration file in Nginx nginx.conf as follows:

HTTP {

Include Mime.types;

Default_type Application/octet-stream;

Sendfile on;

Keepalive_timeout 65;


upstream Web1 {

Server 192.168.1.101:80 weight=1 max_fails=2 fail_timeout=30s;

Server 192.168.1.102: weight=1 max_fails=2 fail_timeout=30s;

}


#web1 Load Module name (custom).

# Weight weights, the higher the value the greater the priority.

#max_fails the maximum number of failures, the list of loads is excluded if the host fails to connect two consecutive times.

#fail_timeout the wait time for the request to fail.


server {

Listen 80;

server_name localhost;

Location/{

Proxy_pass http://web1;

root HTML;

Index index.html index.htm;

}

}

}

#proxy_pass Http://web1; Enable the load module.

Restart the Nginx service after saving the exit.

With access to 192.168.1.100, the load balancer builds successfully if the contents of the two Apache servers are displayed separately.

Nginx Load balancer (based on ip/port)

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.