This is the 12th day of my participation in the August More Text Challenge. For details, see: August More Text Challenge

Today we’re going to look at some of the ways load balancing can be done in Nginx.

First of all, what is load balancing?

What is load balancing?

Load balancing refers to balancing work tasks to a certain extent, or allocating tasks to multiple services. The multiple services can be different Web services or various business system services such as file services.

On the basis of the original resources, it provides a cost-effective and efficient implementation of high intensity, high throughput network services to the original services.

When to use load balancing?

When the system began to have a large number of users access to the server, as well as the volume increase, will face the system caton, even collapse, this time also will have to undertake system was optimized, and the load balancing is one of one of the system optimization scheme, mainly through the load balancing server to traffic equilibrium between the multiple services, to release pressure single service system.

Polling mode (default)

Polling mode is the default load balancing mode in Nginx. Each request in Nginx is allocated to different back-end services one by one according to the access time order. If one of the back-end services fails, this back-end service will be removed.

Weight weight model

Assign a specific weight to each back-end server, which means that different orders of magnitude of front-end requests can be processed depending on the performance of the back-end server.

This pattern is more usable in a real system architecture than the polling pattern.

Ip_hash mode

As can be seen from the name, this mode is related to IP. Ip_hash mode can classify the hash value of each request IP and specify IP to access the specified back-end server. This mode can solve the session problem well.

Of course, in addition to these three, there is also url_hash. Fair model, hope you have a simple understanding, to facilitate the use in the actual situation.