dev-resources.site
for different kinds of informations.
π Deploying Node.js Application with PM2, NGINX, and SSL Configuration π
Published at
10/7/2024
Categories
aws
ssl
nginx
pm2
Author
mahinur05
Author
9 person written this
mahinur05
open
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 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
- 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
- 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
- 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
- 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
pm2 Article's
30 articles in total
Deploy NestJS and NextJS application in same server using pm2 and Nginx
read article
Guia de Comandos PM2
read article
π Deploying Node.js Application with PM2, NGINX, and SSL Configuration π
currently reading
Monitoring PM2 in production
read article
Mastering PM2: Optimizing Node.js and Next.js Applications for Performance and Scalability
read article
Setting Up PM2 for Multi-User Access on Ubuntu Instance
read article
Manual deployment of NestJS and Angular applications on a dedicated server via "Docker Compose" and "PM2"
read article
Build applications on NestJS and Angular and run them in two versions: via PM2 and via Docker Compose
read article
An example of a simple update of NestJS-mod libraries
read article
Using pm2 to Manage Node.js Applications
read article
Using Screen and PM2 for Deploying, Debugging, and Running NestJS in Production
read article
Host Multiple Node Apps with nginx, pm2 with SSL certificate
read article
Node.js PM2 Orchestration Explained
read article
Managing Logs with PM2 and pm2-logrotate
read article
Streamlining PM2 Startup for Node.js Applications: A Comprehensive Guide
read article
Managing Next.js and NestJS Applications in Production with PM2
read article
Deploy a Full Stack Web App to VPS Server with NGINX andΒ PM2!
read article
Como utilizar o PM2 para gerenciar aplicaçáes
read article
Guide to Running a Node Server in Nx Monorepo using PM2 Process Manager
read article
How to run old nodejs Project into new nodejs project
read article
CentOS 7 NodeJS Kurulumu
read article
How to start node.js app with pm2
read article
How to start node.js app with pm2
read article
Deploying Multiple NodeJS Servers on a Single DigitalOcean Droplet; Managed by PM2, Without Using an ecosystem.config.js file
read article
Automatic deploys with PM2, Caddy, and GitHub Actions
read article
Utilizando PM2 (Basico)
read article
Experience on PM2 Tricks to manage your NodeJs processes
read article
Deploy Nest JS App using PM2 on Linux (Ubuntu) Server
read article
Install PM2 (Process Manager 2)
read article
Generate server block (virtual hosts) for nginx dynamically
read article
Featured ones: