Prerequisites
- Ubuntu 20.04 or later
- Domain name pointing to your VM
- Root or sudo access
Step 1: Install Nginx
bash
sudo apt update
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
Step 2: Configure Firewall
bash
sudo ufw allow 'Nginx Full'
sudo ufw allow OpenSSH
sudo ufw enable
Step 3: Install Certbot
bash
sudo apt install certbot python3-certbot-nginx -y
Step 4: Get SSL Certificate
bash
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
Step 5: Auto-renewal Test
bash
sudo certbot renew --dry-run
Verify
Visit https://yourdomain.com
- you should see a secure connection! 🎉
Pro tip: Certbot automatically sets up a cron job for certificate renewal.