How to serve Node js app with NGINX reverse Proxy

In this post I will show you How we can use NGINX web server as Revers Proxy server. NGINX is very powerfull, It can handle at least 10,000 simultaneous client connections on a single server with its event driven architecture.

In simple words NGINX is

– Open source and its free to use.
– High Performance HTTP Server.
– Can be used as Revers Proxy
– Can be used as IMAP/POP3 Proxy Server.
– Simple and easy to configure.
– High Performance, stable and low resource consumption.
– Event Driven Asynchronous architecture.

To start off, we need to install and configure nginx which will serve the front end of our site.

Installing Nginx on Ubuntu 16.04

Once it has installed, you can Check status of Nginx and start it using the following commands:-

Make sure that Nginx will run on system startup by using command below:-

Nginx should be up and running, now we need configure NGINX as Proxy for Node JS application.

Now update your server block same as below shown. It should look something like this:-

Replace with your ec2 domain name and private_ip_address with the private ip address associated ( which you obtained previously)

Save and quit file using wq vim command.

Test the configuration of Nginx using the command below:-

Then reload Nginx if OK is displayed.

Create your first Nodejs application using Expressjs
Create your project directory and install Expressjs

Create a simple express application

and make it listen at port 8080 and private_ip_address. It should look something like this:-

Replace private_ip_address with your private ip address.

Run your app by using the command below:-

Now open your browser and browse your domain. It should display Hello World!.

Nginx is now setup as a reverse proxy for your application.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.