This guide walks you through deploying the TravelMemory MERN application on AWS EC2, securing it using Cloudflare + Let’s Encrypt SSL, and scaling with multiple instances and a Load Balancer.
- MERN (MongoDB, Express, React, Node.js)
- AWS EC2 (Ubuntu 22.04 LTS)
- NGINX (Reverse Proxy)
- Cloudflare (DNS + SSL)
- Certbot (HTTPS SSL)
- PM2 (Node process manager)
- Load Balancer (Application Load Balancer - optional for scaling)
- AWS account
- Domain name (e.g., from GoDaddy or Namecheap)
- Cloudflare account (Free tier is enough)
-
Go to AWS EC2 Dashboard
-
Launch instance:
- OS: Ubuntu 22.04 LTS
- Type: t2.micro (Free Tier)
-
Configure Security Group: Allow
- HTTP (80)
- HTTPS (443)
- SSH (22)
- Custom TCP (3000)
ssh -i /path/to/key.pem ubuntu@EC2_PUBLIC_IPUpdate and install packages:
sudo apt update && sudo apt upgrade -y
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs npm git nginx
sudo npm install -g pm2git clone https://github.com/UnpredictablePrashant/TravelMemory.git
cd TravelMemory/backend
npm installIf start script is missing, add to package.json:
"scripts": {
"start": "node index.js"
}Start backend:
pm2 start index.js --name travel-backendcd ../frontend
npm installUpdate src/urls.js:
export const backendUrl = "/api";Then build the frontend:
npm run build
sudo cp -r build/* /var/www/html/sudo nano /etc/nginx/sites-available/travelmemoryPaste the config:
server {
listen 80;
server_name memoriesnverfade.in www.memoriesnverfade.in;
location /api {
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;
}
location / {
root /var/www/html;
index index.html;
try_files $uri $uri/ =404;
}
}Enable and test:
sudo ln -s /etc/nginx/sites-available/travelmemory /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx- Login to Cloudflare Dashboard
- Click Add Site and enter
memoriesnverfade.in - Choose Free Plan and continue
- Cloudflare will provide two nameservers
- Go to your domain registrar (e.g., GoDaddy)
- Replace default nameservers with Cloudflare’s
| Type | Name | Content | Proxy |
|---|---|---|---|
| A | @ | EC2_PUBLIC_IP | Proxied ✅ |
| CNAME | www | @ | Proxied ✅ |
- Go to SSL/TLS tab in Cloudflare
- Set SSL Mode to Full (strict)
sudo apt install certbot python3-certbot-nginx -yRun SSL command:
sudo certbot --nginx -d memoriesnverfade.in -d www.memoriesnverfade.inTest auto-renew:
sudo certbot renew --dry-run-
Create multiple EC2 instances using your configured AMI
-
Use an Application Load Balancer (ALB):
- Add both frontend and backend EC2 instances to Target Groups
- Configure ALB Listener Rules (port 80 → NGINX)
-
Point Cloudflare DNS A record to the ALB DNS name instead of single EC2 IP
Client (Browser)
│
▼
Cloudflare (DNS + SSL)
│
▼
Application Load Balancer (optional)
│
┌────┴────┐
▼ ▼
NGINX Node.js (3000)
│
▼
React Build (/var/www/html)
https://memoriesnverfade.in- NGINX config test:
sudo nginx -t - PM2 logs:
pm2 logs travel-backend - Check EC2 Security Group for open ports
- Test domain DNS: https://dnschecker.org
Your MERN app is deployed, secure, and scalable!
Built with ❤️ by Vignesh