High Availability with NginX on Windows
Hello, my name is Rofi and today I shall tell my story on how to setup High Availability on your own Windows laptop!
The steps shown in this tutorial is for Windows 10, as it is my main Operating System. The steps for other Operating Systems may be different.
Step 1: Install NginX
You can install the stable version of NginX here.
After that, extract the folder nginx-1.16.1 and place it so it is level with your project folder like in the following illustration:
Step 2: Setting up NginX
Before we start using NginX, we need to edit some configuration files to set up the load balancer. The file you need to edit is “../nginx-1.16.1/conf/nginx.conf” and add the highlighted codes to the program like so:
Note: Before editing it is best to have a backup file for the conf file, just in case something goes wrong.
I had help with this code from my friend Okto and Iqrar. This is all you need to setup NginX. Of course there are many ways to set it up according to your own needs. In my case, I set it up so I can use two parts which are localhost:8000 and localhost:9000.
Step 3: Start NginX
To start NginX in Windows. Open a terminal in the NginX folder and type in a command like so:
If you open localhost now in your browser this is what you should see:
Step 4: Using NginX
Now open your djangoapp project and run 2 django servers. For the first one, I ran:
python manage.py runserver localhost:8000
and also:
python manage.py runserver localhost:9000
If you open localhost, now you should get the website you are trying to run. In my example, I am running one of my django projects:
To test the load balancer. You can try and stop one of the servers and see if it still runs. For example I stopped the server for localhost:8000 like so:
As you can see, the website is still running. But what if we stopped both servers? Lets see:
It stopped running, because there aren’t any servers that can fulfill the request and NginX will display an error page.
Conclusion
And that is it! Easy right? Now you now know how to setup for simple high availability server with NginX on your Windows Computer. There are many tools for high availability setup like this for example “Linux Virtual Server” and many others. Feel free to explore!