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