Home  >  Article  >  Backend Development  >  nginx server load balancing configuration

nginx server load balancing configuration

WBOY
WBOYOriginal
2016-08-08 09:20:51957browse

Commonly used load balancing solutions include the following:
1. Polling
Polling is Round Robin, which distributes the client's Web requests to different back-end servers in sequence according to the order in the Nginx configuration file.
Configuration examples are as follows:
http{
upstream sampleapp {
                                                                                                            using use using using                       out out through off ‐ off ‐ ‐ ‐ ‐ down ‐ , and )>>;
}
....
server{
listen 80;
}
2. Minimum connection
Web request will be Forwarded to the server with the fewest connections.
Configuration examples are as follows:
http{
upstream sampleapp {
  least_conn;
                                                                                                                  use   using   use using                   through   through   through   through off out through out through out through out through out through out through out through through’'s to ‐‐‐ ‐‐‐‐ ​ to optional with port)> }
3. IP hash
as mentioned above In the two load balancing solutions, continuous web requests from the same client may be distributed to different back-end servers for processing, so if a session is involved, the session will be more complicated. Common is database-based session persistence. To overcome the above problems, you can use a load balancing solution based on IP address hashing. In this case, consecutive web requests from the same client will be distributed to the same server for processing.
Configuration examples are as follows:
http{
upstream sampleapp {
ip_hash;
server <>;
server < }
4. Weight-based load Balance
In this way, we can configure Nginx to distribute more requests to high-configuration back-end servers and distribute relatively few requests to low-configuration servers.
An example of the configuration is as follows:
http{
upstream sampleapp {
                                                                                                        through   using using using                 through out through Through out Through out Through OUT out through off ‐ ‐ ‐ ‐ ‐ server < optional with port)> }
The above example is in the server address and the configuration of weight=2 after the port, which means that for every 3 requests received, the first 2 requests will be distributed to the first server, the third request will be distributed to the second server, and other configurations are in the same cycle. Query configuration.

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.


The above introduces the nginx server load balancing configuration, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn