nginx implements load balancing

What is load balancing
Load balancing is built on the existing network structure, which provides a cheap, effective and transparent method to expand the bandwidth of network devices and servers, increase throughput, strengthen network data processing capabilities, and improve network flexibility and availability. .
Load balancing, the English name is Load Balance, means that it is allocated to multiple operation units for execution, such as Web servers, FTP servers, enterprise key application servers and other mission-critical servers, so as to complete work tasks together.

nginx implements load balancing
1.
nginx is required as a load balancing server. User requests reach nginx first, and then nginx forwards the request to the tomcat server according to the load configuration.
nginx load balancing server: 192.168.101.3
tomcat1 server: 192.168.101.5
tomcat2 server: 192.168.101.6
write picture description here

2. Configuration
According to the above requirements, configure load balancing in the nginx.conf file, 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 balancing 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 ;
status of each upstream device:

down means that the server before the order does not participate in the load temporarily. The
default weight is 1. The larger the weight, the greater the weight of the load.
max_fails : The default number of allowable requests to fail is 1. When the maximum number of times is exceeded, the error defined by the proxy_next_upstream module will be returned.
fail_timeout: The time to pause after max_fails failures.
backup: When all other non-backup machines are down or busy, request the backup machine. So this machine will be the least stressful.

4. Test
Request aaa.test.com, and forward the request to the tomcat server through nginx load balancing.
By observing the access log of tomcat or the access page of tomcat, you can know which tomcat server accepts the current request.

Refer to Mr. Yunlong's class notes

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324462868&siteId=291194637