I am going to explain the process of load balancing the web application using Nginx
Pre-requisites
- One machine with Nginx installation
- Two machines with running the same web application
Test setup
All are Ubuntu server machines- 10.10.1.1 - Load Balancer
- 10.10.1.2 - Node 1
- 10.10.1.3 - Node 2
Configuration
In the Nginx server machine (10.10.1.1) do the following load balancing configuration- Make sure you stop the nginx server if running
$ sudo service nginx stop
- Edit the nginx.conf file
$ sudo vi /etc/nginx/nginx.conf
- Place the following sample content
http {
upstream testsetup {
server 10.10.1.2;
server 10.10.1.3;
}
server{
listen 8090;
server_name testsetup;
location / {
proxy_pass http://testsetup;
}
}
}
- Start the Nginx server
$ sudo service nginx start
Load Balancing Test
- Access the 10.10.1.1:8090 in the web browser
- It will redirect to Node 1 (10.10.1.2)
- Refresh/Reload the page, the load balancer redirects to Node 2 (10.10.1.3)
Tip
To differentiate the web server, add a footer with different content (Static IP Address) in your index.htmlPlease send your comments and feedback to psrdotcom@gmail.com
No comments:
Post a Comment