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
ssl Article's
30 articles in total
Building and Deploying a New API (Part 3)
read article
Using Cloudflare SSL with Elastic Beanstalk instances
read article
Generate your Let's Encrypt Digital Certificates for all your domains using Apache
read article
Renew LetsEncrypt SSL Certificate in WordPress by Bitnami
read article
Building an S3 Static Website with CloudFront Using Terraform
read article
You May Prefer to Know Less About PKI Flaws but Now Is Too Late
read article
Understanding SSL and Its Importance
read article
Heartbleed: The Bug That Shook the Internet
read article
How to Ignore cURL SSL Errors
read article
Secure Nginx with Let's Encrypt on Ubuntu
read article
How to Update SSL Certificate in SafeLine WAF through a File
read article
Deploy Vite-React Project in AWS EC2 using custom domain and free SSL Certificate.
read article
5 Steps for a Quick and Effective Transition to 90-Day TLS/SSL Certificates
read article
Guide to SSL Errors: What do they mean and how to fix them
read article
How to remotely EV code-sign a windows application using ssl.com
read article
Instant Domain Insights: Why Every Tech Professional Needs DNS Checker Pro
read article
INSY 8211 & Intro to Linux Administration - part_1 [Network and Web Server Configuration]
read article
Day 32: Securing Your Personal Blog with SSL/TLS (A Beginner's Guide)
read article
Understanding SSL/TLS: The Role of Encryption and Security Protocols in Internet Communication
read article
Get a free SSL certificates for your shared-hosting cPanel domain!
read article
Choosing an SSL certificate: paid or free β or whether you can do without one
read article
Chain of Trust: Decoding SSL Certificate Security Architecture
read article
Docker Server Certificate with SSL
read article
HTTPS and SSLs: Why They Matter, How to Use Them
read article
π Deploying Node.js Application with PM2, NGINX, and SSL Configuration π
currently reading
Types of SSL Certificates
read article
AWS Certificate Manager Implementation
read article
Migration vom Nginx Proxy Manager zu Traefik π
read article
Migrating from Nginx Proxy Manager to Traefik π
read article
Self hosted supabase setup with Authelia and Caddy
read article
Featured ones: