Configure Nginx as a web server and reverse proxy for Nodejs application on Azure Windows


NodeJs applications are “Single threaded Event Loop” i.e there is a single thread listening to all incoming requests. On receiving a request, it immediately publish it to its internal “event queue” and is ready to receive the next request. It also polls event queue for any pending tasks and processes Non-blocking I/O tasks. For any blocking I/O tasks like (interfacing with database, file system) it picks up a free thread from its internal thread pool and assign this request to it.

Image Credits –

Keeping NodeJs servers up are hard. Whenever a node.js error is unhandled, it unwinds the stack and leaves v8 in an unrecoverable state. The only recovery is to restart the process. There are few modules that help and PM2 seems to be the most popular.

For public facing website, you shouldn’t run Node app on port 80. This exposes node servers to internet traffic. Instead you should run the app on a different port like 3000 and use nginx as a reverse proxy in front of the Node.js app. You should install SSL on the proxy server. This setup helps you take advantage of cache, scale node servers and load balance them.

Nginx can be used as web server, reverse proxy, load balancer and HTTP cache.

Image Credits –

Installing Nginx on Azure VM Instance with Windows

  • Download Nginx from
  • Unpack the file in c:\nginx and start a command prompt
  • Go to C:\nginx and runnginx.exe
  • You should be able to go to http://localhost/ and you should see the “Welcome to Nginx” default page. If you see that page, then we can be sure that Nginx has been installed properly.

Install Nginx Windows Service

We will be using the WINSW to create a service out of the existing Nginx binaries. The first step is to download WINSW and save it in the same folder as Nginx asnginx-winsw.exe.

Now create a file, named nginx-winsw.xmlwith following contents and place it inside Nginx folder.


You are now ready to install and run the Windows service, you can proceed to run the following commands:

C:/nginx/nginx-winsw.exe install
C:/nginx/nginx-winsw.exe start

At this point, you have Nginx as a service and you can set it up to start automatically after machine boot!

Install SSL Certificate on Nginx

To encrypt communication between user and proxy server, you should have SSL certificate.

Self-signed TLS certificates are suitable for personal use or for applications that are used internally within an organization. How to create a self signed certificate

For internet facing applications, you should get certificate from trusted Certificate Authority. First, you have to generate a private key, called, and a CSR, called using openssl . Run this command (replace the with the name of your domain).

openssl req -newkey rsa:2048 -nodes -keyout -out

At this point, you will be prompted for several lines of information that will be included in your certificate request. The most important part is the Common Name field which should match the name that you want to use your certificate with — for example,,, or (for a wildcard certificate request) *

This will generate you two files:

    Your Private key. You’ll need this later to configure NGINX.
    Your CSR file.

You will need to copy and paste your certificate content to request for a SSL Certificate with a Certificate Authority.

Download Certificate

Once your domain is verified, you will receive an email with a link to download SSL certificate. Download .crt files inside C:/nginx/bin/certs.

If your Certificate Authority included an intermediate certificate, you must create a single chained certificate file that contains your certificate and the CA’s intermediate certificates.

type intermediate.crt >

Open NGINX config points to the right cert file and to the private key you generated.

You should install SSL on the proxy server

3 thoughts on “Configure Nginx as a web server and reverse proxy for Nodejs application on Azure Windows

Leave a Reply

Your email address will not be published. Required fields are marked *