Facebook Pixel

Custom Domain Setup Summary and Checklist Complete Guide for Node.js Deployment

A comprehensive summary and checklist for setting up a custom domain name for your Node.js application from buying to DNS to SSL to verification.

Custom Domain Setup Summary and Checklist

This is a complete summary of everything needed to set up a custom domain for your Node.js application on AWS EC2.

The Complete Process

1. Buy a domain name
2. Allocate an Elastic IP on EC2
3. Configure DNS records (A record)
4. Configure Nginx server blocks
5. Add SSL with Let's Encrypt
6. Update backend CORS and cookies
7. Update frontend environment variables
8. Verify everything works
9. Set up monitoring and auto-renewal

Step-by-Step Checklist

1. Buy a Domain

  • Choose a short, brandable domain name
  • Select a TLD (.com recommended)
  • Buy from Namecheap or Cloudflare
  • Enable WHOIS privacy
  • Enable auto-renewal
  • Enable 2FA on your registrar account

2. Allocate Elastic IP

  • Go to AWS Console → EC2 → Elastic IPs
  • Click Allocate Elastic IP address
  • Associate with your EC2 instance
  • Note the IP address (e.g., 12.34.56.78)

3. Configure DNS

  • Set up Cloudflare for DNS (recommended) or use registrar's DNS
  • Update nameservers at the registrar (if using Cloudflare)
  • Create A record: @ → EC2 IP (root domain)
  • Create A record: api → EC2 IP (API subdomain)
  • Create A record: app → EC2 IP or CNAME for Vercel
  • Create CNAME: www → yourdomain.com
  • Verify with dig yourdomain.com A +short

4. Configure Nginx

  • Create server block for api.yourdomain.com (proxy to Node.js)
  • Create server block for app.yourdomain.com (static files)
  • Create server block for yourdomain.com (redirect to app)
  • Add WebSocket headers for /socket.io/
  • Add proxy headers (Host, X-Real-IP, X-Forwarded-For, X-Forwarded-Proto)
  • Remove the default site
  • Test with sudo nginx -t
  • Reload with sudo systemctl reload nginx

5. Add SSL

  • Install certbot: sudo apt install certbot python3-certbot-nginx
  • Get certificate: sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com -d api.yourdomain.com -d app.yourdomain.com
  • Verify HTTPS: curl -I https://yourdomain.com
  • Test auto-renewal: sudo certbot renew --dry-run

6. Update Backend

  • Set CLIENT_URL=https://app.yourdomain.com in .env
  • Update CORS: origin: ["https://app.yourdomain.com"]
  • Set app.set("trust proxy", 1) in Express
  • Update cookie settings: secure: true, sameSite: "none", domain: ".yourdomain.com"
  • Restart PM2: pm2 restart devtinder-api

7. Update Frontend

8. Verify

9. Monitoring and Maintenance

  • Set up UptimeRobot for uptime monitoring
  • Set up SSL expiry alerts
  • Set up domain expiry alerts
  • Enable certbot auto-renewal (default)
  • Document all DNS records
  • Export DNS records as backup

Architecture Summary

User visits app.yourdomain.com
    ↓
DNS resolves to EC2 Elastic IP (via Cloudflare)
    ↓
Cloudflare (CDN, DDoS protection, SSL)
    ↓
Nginx (port 443, SSL, reverse proxy)
    ↓
Node.js (port 3000, Express, Socket.io)
    ↓
MongoDB Atlas

DNS Records Summary

TypeNameValuePurpose
A@EC2 IPRoot domain
AapiEC2 IPAPI subdomain
AappEC2 IPFrontend subdomain
CNAMEwwwyourdomain.comwww redirect

Nginx Server Blocks Summary

server_nameAction
api.yourdomain.comProxy to localhost:3000
app.yourdomain.comServe static files from dist/
yourdomain.com301 redirect to app.yourdomain.com

Environment Variables Summary

Backend (.env):

PORT=3000 MONGODB_URI=mongodb+srv://... JWT_SECRET=... NODE_ENV=production CLIENT_URL=https://app.yourdomain.com

Frontend (.env):

VITE_API_URL=https://api.yourdomain.com/api VITE_SOCKET_URL=https://api.yourdomain.com

The Takeaway

Setting up a custom domain involves: buying a domain, allocating an Elastic IP, configuring DNS (A records and CNAME), setting up Nginx server blocks for each subdomain, adding SSL with Let's Encrypt, updating backend CORS and cookie settings, updating frontend environment variables, and verifying everything works. Use Cloudflare for free DNS, CDN, and DDoS protection. Set up monitoring and auto-renewal for long-term maintenance.

Buy a domain, allocate an Elastic IP, configure DNS records (A and CNAME), set up Nginx server blocks for each subdomain, add SSL with Let's Encrypt, update backend CORS and cookies, update frontend env vars, verify everything works, and set up monitoring and auto-renewal.

A record for @ (root domain) pointing to EC2 IP, A record for api subdomain pointing to EC2 IP, A record for app subdomain pointing to EC2 IP (or CNAME to Vercel), and CNAME for www pointing to yourdomain.com.

Backend: CLIENT_URL=https://app.yourdomain.com. Frontend: VITE_API_URL=https://api.yourdomain.com/api and VITE_SOCKET_URL=https://api.yourdomain.com. Also update CORS origins and cookie settings (secure: true, sameSite: none, domain: .yourdomain.com).

Check DNS (dig yourdomain.com A +short), HTTP to HTTPS redirect (curl -I http), HTTPS (curl -I https), API (curl https://api.yourdomain.com/api/health), frontend loads in browser, login works, cookies persist on refresh, WebSocket chat works, and SSL grade at ssllabs.com.

UptimeRobot for uptime monitoring (free), SSL expiry alerts (to avoid certificate expiration), domain expiry alerts (30, 15, 7 days before), certbot auto-renewal (enabled by default), and document all DNS records as backup.

Ready to master Node.js completely?

Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.

Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.