- Next.js (App Router)
- TypeScript
- NextAuth.js
- Resend Email API
- MongoDB Atlas
- Docker & Docker Compose
- AWS EC2 (Ubuntu 22.04)
- Nginx (Reverse Proxy)
- Cloudflare DNS
- Let's Encrypt SSL (Certbot)
- GitHub (SSH authentication)
-
OS: Ubuntu latest(24.04)
-
Instance: ** t3.micro** (free tier)
-
Security Group:
- SSH →
22 - HTTP →
80 - HTTPS →
443all 3 ports can be accesed from anywhere
- SSH →
cd /c/Users/YourName/path-to-key
chmod 400 key.pem
ssh -i key.pem ubuntu@EC2_PUBLIC_IPsudo apt update && sudo apt upgrade -y
sudo apt install -y curl git unzipsudo apt install -y docker.io
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker ubuntu
newgrp dockerVerify:
docker --versionsudo apt install docker-compose -y
docker-compose --versionGenerate key:
ssh-keygen -t ed25519 -C "ec2-deploy"
cat ~/.ssh/id_ed25519.pub➡ Add the key to GitHub → Settings → SSH Keys
Clone repo:
mkdir ~/apps && cd ~/apps
git clone git@github.com:USERNAME/REPOSITORY.git
cd REPOSITORYCreate .env:
nano .envNODE_ENV=production
NEXTAUTH_URL=https://subdomain.yourdomain.com
DATABASE_URL=###############################Save: CTRL + O → Enter → CTRL + X
services:
app:
build: .
container_name: project_app
env_file:
- .env
ports:
- "3000:3000"
restart: unless-stoppedBuild & run:
docker-compose build
docker-compose up -dCheck:
docker pssudo apt install -y nginx
sudo systemctl start nginx
sudo systemctl enable nginxCreate config:
sudo nano /etc/nginx/sites-available/yourappserver {
listen 80;
server_name subdomain.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;
}
}Enable:
sudo ln -s /etc/nginx/sites-available/yourapp /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginxAdd record:
Type: A
Name: subdomain
Value: EC2_PUBLIC_IP
Proxy: ON
TTL: Auto
Verify:
ping subdomain.yourdomain.comInstall Certbot:
sudo apt install -y certbot python3-certbot-nginxGenerate certificate:
sudo certbot --nginx -d subdomain.yourdomain.comAuto‑renew test:
sudo certbot renew --dry-runReplace:
0.0.0.0/0
With:
EC2_PUBLIC_IP/32
✔ Improves security
free -h
docker stats
df -h- HTTPS enabled
- HTTP → HTTPS redirect
- Containers healthy
- MongoDB connected
- Nginx active
- Certbot auto‑renew enabled
- Cloudflare resolving correctly