๐Ÿš€ Deploying Node.js Application with PM2, NGINX, and SSL Configuration ๐Ÿš€

Today, I deployed a new Node.js app on AWS using a smooth setup process with Node.js, PM2, NGINX, and Certbot for SSL(no need to touch cpanel). Only 5 steps to deploy your app in AWS. Hereโ€™s the step-by-step guide that can save time for you!

Install …


This content originally appeared on DEV Community and was authored by Mahinur Rahman

Today, I deployed a new Node.js app on AWS using a smooth setup process with Node.js, PM2, NGINX, and Certbot for SSL(no need to touch cpanel). Only 5 steps to deploy your app in AWS. Hereโ€™s the step-by-step guide that can save time for you!

  1. Install Node.js & NPM:


sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/nodesource.list > /dev/null
sudo apt-get update
sudo apt-get install nodejs -y
sudo apt install npm -y
npm i -g n
sudo n lts


  1. Clone Your Repo and Setup PM2:


git clone <your-repo>
cd <your-repo-directory>
git checkout <branch-name>
npm install
sudo npm i -g pm2@latest
pm2 init


  1. Configure PM2 with a Template:


module.exports = {
  apps: [
    {
      name: 'your-app-name',
      cwd: '/home/ubuntu/my-project',
      script: 'npm',
      args: 'start',
      env: {
        "KEY": "value",
      },
    },
  ],
};


  • Make a subdomain first, then
  • Now add A record in your DNS - CPANEL for the public IP where your instance is live (example 3.107.76.239) and set TTL to 300
  1. Configure NGINX for Reverse Proxy:


sudo apt install nginx
sudo nano /etc/nginx/sites-available/default


  • Set the domain and point your port in NGINX config:


server {
    listen 80;
    server_name yourdomain.com;
    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}


  • Restart NGINX:


sudo systemctl restart nginx



  1. SSL Configuration with Certbot (NO TOUCH NEEDED IN CPANEL):


sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com


Now you have your Node.js app running securely with an SSL-enabled domain ๐ŸŽ‰
๐Ÿ”— DM me if you'd like more tips on server setup, Node.js deployment, or other dev-related topics.

Nodejs #AWS #DevOps #PM2 #Nginx #SSL #FullStack #WebDev


This content originally appeared on DEV Community and was authored by Mahinur Rahman


Print Share Comment Cite Upload Translate Updates
APA

Mahinur Rahman | Sciencx (2024-10-07T15:43:09+00:00) ๐Ÿš€ Deploying Node.js Application with PM2, NGINX, and SSL Configuration ๐Ÿš€. Retrieved from https://www.scien.cx/2024/10/07/%f0%9f%9a%80-deploying-node-js-application-with-pm2-nginx-and-ssl-configuration-%f0%9f%9a%80/

MLA
" » ๐Ÿš€ Deploying Node.js Application with PM2, NGINX, and SSL Configuration ๐Ÿš€." Mahinur Rahman | Sciencx - Monday October 7, 2024, https://www.scien.cx/2024/10/07/%f0%9f%9a%80-deploying-node-js-application-with-pm2-nginx-and-ssl-configuration-%f0%9f%9a%80/
HARVARD
Mahinur Rahman | Sciencx Monday October 7, 2024 » ๐Ÿš€ Deploying Node.js Application with PM2, NGINX, and SSL Configuration ๐Ÿš€., viewed ,<https://www.scien.cx/2024/10/07/%f0%9f%9a%80-deploying-node-js-application-with-pm2-nginx-and-ssl-configuration-%f0%9f%9a%80/>
VANCOUVER
Mahinur Rahman | Sciencx - » ๐Ÿš€ Deploying Node.js Application with PM2, NGINX, and SSL Configuration ๐Ÿš€. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/07/%f0%9f%9a%80-deploying-node-js-application-with-pm2-nginx-and-ssl-configuration-%f0%9f%9a%80/
CHICAGO
" » ๐Ÿš€ Deploying Node.js Application with PM2, NGINX, and SSL Configuration ๐Ÿš€." Mahinur Rahman | Sciencx - Accessed . https://www.scien.cx/2024/10/07/%f0%9f%9a%80-deploying-node-js-application-with-pm2-nginx-and-ssl-configuration-%f0%9f%9a%80/
IEEE
" » ๐Ÿš€ Deploying Node.js Application with PM2, NGINX, and SSL Configuration ๐Ÿš€." Mahinur Rahman | Sciencx [Online]. Available: https://www.scien.cx/2024/10/07/%f0%9f%9a%80-deploying-node-js-application-with-pm2-nginx-and-ssl-configuration-%f0%9f%9a%80/. [Accessed: ]
rf:citation
» ๐Ÿš€ Deploying Node.js Application with PM2, NGINX, and SSL Configuration ๐Ÿš€ | Mahinur Rahman | Sciencx | https://www.scien.cx/2024/10/07/%f0%9f%9a%80-deploying-node-js-application-with-pm2-nginx-and-ssl-configuration-%f0%9f%9a%80/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.