Nginx as Load Balancer Server--Test

Source: Internet
Author: User

I. Demand

Nginx as a load balancer server, the user requests to reach nginxFirst, and then by Nginx According to the load configuration to forward the request to Tomcat server.

Nginx Load Balancer server:192.168.101.3

TOMCAT1 server:192.168.101.5

TOMCAT2 server:192.168.101.6

Ii. Configuration

Configure load Balancing in the nginx.conf file based on the requirements above , as follows:

Upstream tomcat_server_pool{

Server 192.168.101.5:8080 weight=10;

Server 192.168.101.6:8080 weight=10;

}

server {

Listen 80;

server_name aaa.test.com;

Location/{

Proxy_pass Http://tomcat_server_pool;

Index index.jsp index.html index.htm;

}

}

Node Description:

Add in the HTTP node :

# define the Ip and device status of the load balancer device

Upstream MyServer {

Server 127.0.0.1:9090 down;

Server 127.0.0.1:8080 weight=2;

Server 127.0.0.1:6060;

Server 127.0.0.1:7070 backup;

}

add under the Server node that needs to use the load

Proxy_pass Http://myServer;

Upstream the status of each device :

Down indicates that the server is temporarily not participating in the load

Weight By default , the larger the 1.weight , the greater the load weight.

Max_fails : The default number of times to allow requests to fail is 1. when the maximum number of times is exceeded, the return Proxy_next_upstream module-defined error

Fail_timeout:max_fails The time of the pause after the failure.

Backup: When all other non- backup machines are down or busy, request the backup machine. So the pressure on this machine is the lightest.

Iii. Test

Request aaa.test.com, via nginx Load balancer, to forward the request to the Tomcat server.

you can see which Tomcat Server The current request is accepting by observing the Tomcat Access log or the Tomcat access page .

Nginx as Load Balancer Server--Test

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.