How to Set Up SSL & Redirect Domain from HTTP to HTTPS on AWS

Connect Your Domain to AWS EC2

Buy a domain & open DNS settings (example: GoDaddy)

Open DNS Zone settings
Add a new A record

Example: Point subdomain to AWS EC2

Host: api
Domain: api.localhostak.online
Type: A
Value: YOUR_EC2_PUBLIC_IP
TTL: 600

Update NGINX Config for New Domain

Add your server name inside the port 80 block

sudo nano /etc/nginx/sites-available/default

Example:

sudo systemctl reload nginx

Install Certbot for SSL

Install Certbot + NGINX plugin

sudo apt update
sudo apt install certbot python3-certbot-nginx -y

Generate Free SSL Certificate

Run certbot

sudo certbot --nginx -d api.localhostak.online