- AWS
- EC2
- Node.js
- NGINX
- PM2
- DevOps
Deploying Node.js Applications with NGINX and PM2 on EC2
Complete guide to deploying robust Node.js applications using NGINX reverse proxy and PM2 process manager on AWS EC2, including free SSL setup with Certbot

Shahid Monowar
· 3 min read
What you'll learn
- Put NGINX in front of your Node.js app as a reverse proxy
- Keep the app running through crashes and reboots with PM2
- Add free HTTPS with Certbot, including automatic renewal
- A final checklist and fixes for the most common errors
Introduction to EC2 Deployment
Deploying Node.js applications on AWS EC2 with NGINX and PM2 creates a production-ready environment that's both scalable and reliable. This guide covers:
- Setting up NGINX as a reverse proxy
- Managing Node processes with PM2
- Securing your domain with free SSL certificates
- Automating service startup
Prerequisites
Before starting, ensure you have:
- An AWS account with EC2 access
- A launched EC2 instance (Ubuntu recommended)
- Node.js installed on your instance
- A registered domain name (optional but recommended)
Step 1: NGINX Installation and Setup
Installing NGINX
sudo apt update
sudo apt install nginx -y
sudo systemctl start nginxBasic Configuration
Verify NGINX is running:
sudo systemctl status nginxYou should now be able to access your server's public IP in a browser and see the NGINX welcome page.
Step 2: Configuring NGINX as Reverse Proxy
Edit the default configuration file:
sudo nano /etc/nginx/sites-available/defaultReplace the server block content with:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
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;
}
}Test and restart NGINX:
sudo nginx -t
sudo systemctl restart nginxStep 3: PM2 Application Management
Installing and Running Your App
npm install -g pm2
cd /path/to/your/app
pm2 start app.jsCommon PM2 Commands
| Command | Description |
|---|---|
pm2 list | View running processes |
pm2 logs | Show application logs |
pm2 restart app_name | Restart application |
pm2 delete app_name | Stop and remove application |
Setting Up Startup Script
pm2 startup
pm2 saveThis ensures your Node application restarts automatically if the server reboots.
Step 4: Securing with SSL (Certbot)
Installation
sudo snap install core
sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbotObtaining Certificate
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.comCertbot will automatically:
- Obtain a certificate from Let's Encrypt
- Configure NGINX to use HTTPS
- Set up automatic certificate renewal
Automatic Renewal Verification
Test the renewal process:
sudo certbot renew --dry-runFinal Checklist
✅ NGINX installed and running
✅ Reverse proxy properly configured
✅ Node application running under PM2
✅ PM2 startup configured
✅ SSL certificate installed
✅ Automatic renewal working
Troubleshooting Tips
- 502 Bad Gateway: Check if your Node app is running on the correct port
- SSL Not Working: Verify DNS records point to your EC2 instance
- PM2 Not Persisting: Ensure you ran both
pm2 startupandpm2 save
Conclusion
You've now set up a production-grade Node.js environment on EC2 with:
- NGINX handling HTTP/HTTPS traffic
- PM2 ensuring application availability
- Free SSL certificates from Let's Encrypt
For further optimization, consider:
- Setting up a CI/CD pipeline
- Configuring load balancing
- Implementing monitoring
🚀 Happy Deployment! 🚀
Available for freelance & contract work
Need this built, or fixed, for your product?
I help teams ship and run production web apps: CRMs, ERPs, booking platforms and SaaS with Next.js, Node.js and PostgreSQL, from the first commit to deployment.

Written by
Shahid Monowar
Full-Stack Engineer building CRMs, ERPs and SaaS products with Next.js, Node.js and PostgreSQL. Based in Dhaka, working with teams worldwide.