How to deploy Next.js on AWS EC2 with SSL (HTTPS)
Step 1: Launch ec2 instance
Step 2: Create network inbound roles
Step 3: Create record on route 53 A record for each domain and subdomain
Step 4: Domain configure
Step 5: Open terminal putty or browser
Step 6: Update Sudo Apt
sudo apt updateStep 7: Start to install Node
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bashStep 8: Activate nvm
. ~/.nvm/nvm.shStep 9: Install Node.js
nvm install nodeStep 10: Install Nginx
sudo apt-get install nginxStep 11: Service nginx status for check version,
nginx -vStep 12:
systemctl start nginxStep 13:
systemctl enable nginxStep 14:
systemctl status nginxStep 15: Nginx configuration >> /etc/nginx/sites-available/default
server {
listen 80;
server_name example.com www.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}Step 16: Symbolik link create
sudo nginx -tStep 17:
sudo systemctl reload nginxStep 18:
sudo systemctl status nginxStep 19: To check domain is connected successfully all domain or subdomain
nslookup example.comStep 20: Install PM2
npm i -g pm2Step 21: Start for react project
pm2 start npm --name "admin" -- server.cjsStep 22: Start for next js project
pm2 start npm --name "frontend" -- run startStep 23: Start for node project
pm2 start npm --name "backend" -- app.jsStep 24: SSL Enable by certbot
sudo apt install certbotStep 25:
sudo apt install python3-certbot-nginxStep 26:
sudo certbot --nginx -d example.com -d www.example.com -d server.example.com -d admin.example.comStep 27:
sudo certbot renew --dry-run