How to Setup Nginx Load Balancing?

How to Setup Nginx Load Balancing?

If you are using Nginx as your web server, you can setup load balancing technique using Nginx. It is very useful technology to distribute the incoming network across a number of servers. Using Nginx load balancing you can lower the response time, reduce the resource usage and avoid the load spike of the server.  Nginx load balancing is one of the most efficient mechanisms which is able to achieve the redundancy of full application and is very easy without any complications to setup. You can set up with the round robin algorithm, which is fairly easy to implement. By using the round robin method, it will forward all requests to the corresponding server included in the Nginx configuration. Let’s have a look into the setup of the Nginx load balancing.


Let’s start with the installation and initial configuration of the Nginx.

1)  Login to your server via SSH as root.

# ssh [email protected]

2) Always it is a good practice to follow before any new installations make sure that the currently installed packages are up to date.

# yum update all -y

3) Install Nginx web server.

#  yum install nginx  -y

4) After the installation checks the status of the nginx.

# service nginx status

5) Append the load balancing configuration. Open the nginx configuration file of your domain with your favorite text editor.

# vi /etc/nginx/sites-available/

Now append the load balancer configuration at the top of the file.

upstream loadbalancer {





Here I have used the word server with the number, instead of this, you can use your server hostname. Make sure all the servers mentioned above must have Nginx installed and listening on 80 port.

5) Enable the upstream module. In the same configuration file itself, you need to add the upstream module on the virtual host configuration.

server {

location / {

proxy_pass http://loadbalancer;



6) After this, save the file and restart the Nginx server to get reflected by the changes made.

# service nginx restart

The changes we made using the upstream module will equally distribute all the incoming traffic among the three servers.

7) Weight Balancing, it can also be configured it distribute the traffic according to your need. That is, you can assign the servers to get the traffic accordingly. It can be done using an option called Weight balancing.

As an example refer to the following entry.

upstream loadbalancer {

server weight=2;

server weight= 4;

server weight=5;


Here will get twice as the traffic as that of the and the will get five times above the traffic as that of the

Likewise, you can configure Nginx Load balancing.


If you need any further assistance please contact our support department.


  • 0

Install Wine on Linux Distribution

Install Wine on Linux Distribution In this tutorial, we can check how to Install Wine on Linux...

Install Apache Tomcat on Ubuntu 18.04

Install Apache Tomcat on Ubuntu 18.04 The Apache Tomcat is a free, open-source Java-based web...

How to Install and Setup Angular CLI

How to Install and Setup Angular CLIAngular is an open-source framework for your web...

How to Install Jenkins on CentOS and Ubuntu Server?

How to Install Jenkins on CentOS and Ubuntu Server? Jenkins is a free and open-source automation...

Setup ILIAS LMS on Ubuntu 18.04/16.04 with Nginx

ILIAS is an Open-Source Learning Management System. ILIAS LMS offers to develop and realizing...