• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to Configure Nginx Load Balancer in Ubuntu

{{postValue.id}}

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

Prerequesites:

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

Load Balancer Server

Hostname : nginxbalancer.com
Ip Address : 192.168.5.123

Web-server 1

Hostname : webserver1.com
IP address : 192.168.5.146

Web-server 2

Hostname : webserver2.com
IP address : 192.168.5.155


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 192.168.5.146 
server 192.168.5.155 
}

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.

Nginx-web-server-Load-balancerIP

Refresh the tab to see the changes.

Nginx-web-server-Load-balancer-Refresh

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

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

Tags:
nicholas
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

is any one know how to install CROSSROADS Load Balancer?

A

follow this Link : " https://www.linuxhelp.com/set-xr-crossroads-load-balancer-linux/ "

Q

is possible to configure HAProxy Load Balancer in Nginx?

A

follow this link : "https://www.linuxhelp.com/how-to-configure-load-balancer-with-haproxy-for-nginx-in-centos/ "

Q

how to install HAPROXY ?

A

follow this link : "https://www.linuxhelp.com/install-haproxy-load-balancer-ubuntu/"

Q

is same procedure for centos nginx load balancer?

A

follow this link : " https://www.linuxhelp.com/how-to-configure-nginx-as-a-load-balancer-in-centos/ "

Q

How do I generate an .htpasswd file without having Apache tools installed?

A

In Linux (and other Posix): given users John, Mary, Jane, and Jim with passwords V3Ry, SEcRe7, V3RySEcRe7, and SEcRe7PwD, in order to generate a password file named .htpasswd, you would issue:

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Jayce ?
What are the types of table used in IPtables

What are the various types of table used in IPtables and how to use that for my server security?

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.