HTTP Load Balancing with NGINX
Load balancing is a way to improve the distribution of the workload across multiple resources. It maximizes throughput, so users could get served faster. By using load balancing, we also avoid overload of any single resource.
One of the ways to do this is by using NGINX. There are several steps of using NGINX as load balancer, which will be explained below.
Step #1: Installing NGINX for Windows
Download at http://nginx.org/en/download.html . You can read the steps for installing here: http://nginx.org/en/docs/windows.html
Download the stable version because it has fixed all the bugs. You can also download the mainline version, it is the most updated version yet, but it’s still not proven, or not “stable” :)
After that, you can extract it. Then, go inside the folder (which has nginx.exe) and run cmd, then you can use nginx :) Here are following commands for nginx:
“start nginx” for using the load balancer
“nginx -s stop” for stop using nginx
“nginx -s reload” for reloading nginx
Step #2: Configuring HTTP Nginx
In nginx folder, open conf folder and open nginx.conf with any text editor (I used Sublime). Here is my configuration:
And save! After you save, you could run 2 servers that have same content (only locally tho).
Actually using my load balancing….
I use port 11000 and port 9000 for my Django project. Open up cmd from your nginx folder and run the command start nginx.
As you can see, we can run it without specifying the port and it automatically connects to the load balancer and redirects to one of the web server. If you shutdown one of the web servers, it could still be accessed through the other active web server.