In this tutorial, we will be going through the steps to install and configure Node.js, PM2, and NGINX on a Linux system.
curl -o- <https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh> | bash
nvm --version
yum install git -y
nvm install node
git clone https://github.com/Sanjai-R/Nodeapp_niginx.git
npm install pm2 -g
pm2 start index.js
sudo yum install nginx -y
location / {
proxy_pass <http://localhost:3000>;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
In the NGINX configuration file, add a server block for your Node.js application. Within this block, add the following lines:
location / {
proxy_pass <http://localhost:3000>;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
Then, restart NGINX to load the new configuration:
sudo systemctl restart nginx
Your Node.js application should now be accessible through NGINX at your server's IP address or domain name.