Reverse proxy in Nginx
Hello Readers, In this blog we will install node.js and we will make one node.js app and after that we will set up nginx as a reverse proxy.
Step 1: Install node.js
We should always use NVM (node version manager) for installing node.js because it allows us to install and maintain the different versions of node js.
Other commands will only install the latest version but using this we can install whichever version that we want.
Download the script for nvm
Using the below command you can install the node.js using nvm by specifying the specific version
You can check the version of node by using this command.
Npm is package manager in node.js you can verify that npm is installed or not using this command
To work npm packages you need to install this build-essential package
Step 2: create simple node.js application
Create one sample application called hello.js
Test your application
Type localhost:3000 in browser to see the app running
Step 3: Installing PM2
PM2 is process manager in node.js application and makes it possible to run in background as a service.
Use npm to install PM2
-g is for globally
Step 4: set up reverse proxy for node.js app in nginx
We will create a file in sites-available which will transfer the request which is coming on port 3000 to localhost.
Create file called node-app
Create soft link for that
Check status and restart service
Type only localhost in the backend it will transfer the request to port 3000.
For custom domain name:
Add server name in server block
Add hostname in /etc/hosts file
Now restart the server and type hello.local in browser