Deploy your API to Production using Nginx | Best Way

deploying Api to production using Nginx

Node.js Deployment | Api to Production Deployment

Steps to deploy a Node.js app to any cloud using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt

1. Sign up for any cloud service and create an VM

In this tutorial i’m using azure’s vm to accomplish the task and Domain from Namecheap which is free for any github verified student account , and if you have an .edu account then you can access azure’s 100$ sponsorship program without any credit card

2. Create a VM and log in via ssh

I will be using the root user, but would suggest creating a new user

3. Install Node/NPM

4. Clone your project from Github

There are a few ways to get your files on to the server, I would suggest using Git

5. Install dependencies and test app

6. Setup PM2 process manager to keep your app running

You should now be able to access your app using your IP and port. Now we want to setup a firewall blocking that port and setup NGINX as a reverse proxy so we can access it directly using port 80 (http)

7. Setup ufw firewall

In case you can’t access the url then make sure to allow inbound rule for port 80 in the azure’s network security group

8. Install NGINX and configure

Add the following to the location part of the server block

You should now be able to visit your IP with no port (port 80) and see your app. Now let’s add a domain

9. Connect your domain to the VM

In Namecheap go to your DNS section and add the following

Add 2 A record, One for @ and One for www to the public ip address of your vm

Register and/or setup domain from registrar

Use any Trusted domain provided for domains.

It may take a bit to propogate

Add SSL with LetsEncrypt

Now visit https://yourdomain.com and you should see your Node app

Now you have deployed your API to production using Nginx.

Thank you for reading till here and congratulations on deploying your application

Follow Stacked Nerds for more Technology and News Related content

1 Comment

  1. David

    Thanks im going to use this project

Leave a Reply

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