Home » Nginx » Nginx load balancing (upstream) parameter setting

Nginx load balancing (upstream) parameter setting

nginx's upstream currently supports the distribution of
in 5 ways
1, polling (default)

Each request is assigned to different backend servers one by one in chronological order. If the backend server down is dropped, it can be automatically removed.

Upstream backserver {

Server 192.168.0.10;

Server 192.168.0.20;

}

2, specify the weight

The specified polling probability is proportional to the access ratio of weight and is used for uneven performance of the backend server.

Upstream backserver {

Server 192.168.0.10 weight=10;

Server 192.168.0.20 weight=10;


}
3, IP binds ip_hash (Peng Yun is learning to use this mode)

Each request is assigned to the hash result of access IP, so that each visitor fixed access to a backend server to solve the session problem.

Upstream backserver {

Ip_hash;

Server 192.168.0.10:88;

Server 192.168.0.20:80;

}

4, fair (third party)

Allocates requests in response to the response time of the backend server, with a priority allocation with short response time.

Upstream backserver {

Server Server1;

Server server2;

Fair;

}

5, url_hash (third party)

Assign requests to the same backend server by accessing the hash results of the URL, and the back-end server is more efficient for caching.
. URL
Upstream backserver {

Server squid1:3128;

Server squid2:3128;

Hash $request_uri;

Hash_method CRC32;

}

adds
in the server that requires load balancing
Proxy_pass, http://backserver/,


upstream backserver{

Ip_hash;

Server 127.0.0.1:9090 down; (down indicates that the server before single is temporarily not involved in the load)

Server 127.0.0.1:8080 weight=2; (weight defaults to 1.weight, the greater the load weight)

Server 127.0.0.1:6060;

Server 127.0.0.1:7070 backup; requests backup machines when all other non backup machines are down or busy,

}

max_fails: the number of requests allowed to fail is 1. by default. When the maximum number is exceeded, the error returned by the proxy_next_upstream module definition is returned.

Fail_timeout:max_fails times after failure, pause time,

Latest