How to Configure Nginx Load Balancer in Ubuntu

To Configure Nginx Load Balancer in Ubuntu

Nginx is an open source and high performance web server for Linux distributions. It acts as a reverse proxy server and Load Balancer in order to distribute incoming traffic around several virtual private servers. In this article let’s see how to configure Nginx as a load balancer in Ubuntu.


Configuration of Nginx Load Balancer


Setup three servers with any IP and Host name as shown below,

Load Balancer Server

Hostname :
Ip Address :

Web-server 1

Hostname :
IP address :

Web-server 2

Hostname :
IP address :

To install Nginx

Utilize the following command to install the Nginx package.

root@ngnixload:/home/user1# apt-get install nginx
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
nginx-common nginx-core
Setting up nginx (1.10.0-0ubuntu0.16.04.4) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu4) ...
Processing triggers for ufw (0.35-0ubuntu2) ...

Then configure the installed package.

root@ngnixload:/home/user1# vim /etc/nginx/sites-available/default
upstream backend {

server {
listen 80;

location / {
proxy_pass http://backend;



Once the Nginx is configured, open the web-root directory to create a file and add some text in the web server1.

Repeat the above step for webserver2.

root@webserver1:/var/www/html# vim index.html

Lets have a look of a Nginx Load balancer  in web browser with Load balancer IP.


Refresh the tab to see the changes.


Run the following command to check the output in command prompt.

root@ngnixload:/home/user1# curl localhost
root@ngnixload:/home/user1# curl localhost



Thank you! for using Linux Help.

You find this tutorial helpful? Share with your friends to keep it alive.
For more help topics browse our website
Be the first to comment, we value your suggestions. For further queries please comment below.

Tags: Nginx Load balancing Web Server Load balancer Reverse-proxy
user image Author :  Nicholas