: This article mainly introduces the nginx server load balancer configuration. if you are interested in the PHP Tutorial, refer to it. Common load balancing solutions include the following:
1. Round Robin
Round Robin (Round Robin) distributes client Web requests to different backend servers in sequence based on the order in the Nginx configuration file.
The configuration example is as follows:
Http {
Upstream sampleapp {
Server < >;
Server <>;
}
....
Server {
Listen 80;
...
Location /{
Proxy_pass http: // sampleapp;
}
}
2. minimum connections
Web requests are forwarded to servers with the least number of connections.
The configuration example is as follows:
Http {
Upstream sampleapp {
Least_conn;
Server < >;
Server <>;
}
....
Server {
Listen 80;
...
Location /{
Proxy_pass http: // sampleapp;
}
}
3. IP hash
In the preceding two server load balancer solutions, consecutive Web requests from the same client may be distributed to different backend servers for processing. Therefore, if Session is involved, the Session will be complicated. Common is database-based session persistence. To overcome the above problems, you can use the IP address hash-based load balancing solution. In this way, the continuous Web requests of the same client are distributed to the same server for processing.
The configuration example is as follows:
Http {
Upstream sampleapp {
Ip_hash;
Server < >;
Server <>;
}
....
Server {
Listen 80;
...
Location /{
Proxy_pass http: // sampleapp;
}
}
4. weight-based load balancing
In this way, we can Configure Nginx to distribute more requests to high-configuration backend servers and distribute a relatively small number of requests to low-configuration servers.
The configuration example is as follows:
Http {
Upstream sampleapp {
Server < > Weight = 2;
Server <>;
}
....
Server {
Listen 80;
...
Location /{
Proxy_pass http: // sampleapp;
}
}
In the preceding example, weight = 2 is configured after the server address and port, which means that every three requests are received, the first two requests are distributed to the first server, 3rd requests are distributed to the second server. other configurations are the same as those in the round robin configuration.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above introduces the configuration of nginx server load balancer, including some content, and hope to be helpful to friends who are interested in the PHP Tutorial.