Load Balancing in Nginx

Posted By : Himanshu Goyal | 12-Apr-2017

Intro:  When we use multiple servers in the production environment then load balance between these servers must require. Nginx can handle 10K concurrent connections and proxy pass to the backend server.Nginx provides the different ways to use load balance:

1.Round Robin load balancing 

2.Least Connection load balancing 

3.Session Persistence load balancing 

4.Weighted load balancing 

A)Round Robin Load Balancing:  This default load balancing in provide by Nginx.In this requests are provided by one by one to each server.
Example:

http {
    upstream backendserver {
        server http://server1.com;
        server http://server2.com;
        server http://server3.com;
    }

    server {
        listen 80;

        location / {
            proxy_pass http://backendserver;
        }
    }
} 

B)Least Connection load balancing: In this technique, nginx check the load of the server and send the request to a less busy server. 
Ex:
    upstream backendserver {
        least_conn;
        server http://server1.com;
        server http://server2.com;
        server http://server3.com;
    }

C)Session Persistence load balancing: In round-robin, each request equally distributed to each server but in session persistence, the each request of same client bound with the same server except when server unavailable.

Ex:
    upstream backendserver {
        ip_hash;
        server http://server1.com;
        server http://server2.com;
        server http://server3.com;
    }

D)Weighted load balancing: In this technique, we provide the weight to the server in round robin manner.In the example, server3 handle the twice request from server2.

Ex: upstream backendserver {
        server http://server1.com weight=3;
        server http://server2.com weight=2;
        server http://server3.com weight=1;
    }

Thanks

 

About Author

Author Image
Himanshu Goyal

Himanshu is a bright Java ,Mean stack developer and have good knowledge of Hibernate, Spring,FFmepg,Neo4j JSON, Jquery, NODE.JS .His hobbies are learning new things, fitness .

Request for Proposal

Name is required

Comment is required

Sending message..