🔒 How To Secure Nginx with Let’s Encrypt on Ubuntu 20.04
Let’s Encrypt is a Certificate Authority (CA) that provides free SSL/TLS certificates. This tutorial shows how to install Certbot and obtain a free SSL certificate for Nginx.
1Install Certbot
Install Certbot and its Nginx plugin:
sudo apt install certbot python3-certbot-nginx
2Confirm Nginx Configuration
Open your config file and ensure server_name is set:
sudo nano /etc/nginx/sites-available/example.com
server_name example.com www.example.com;
Verify syntax and reload:
sudo nginx -t
sudo systemctl reload nginx
3Allow HTTPS Through Firewall
sudo ufw allow 'Nginx Full'
sudo ufw delete allow 'Nginx HTTP'
4Obtain SSL Certificate
sudo certbot --nginx -d example.com -d www.example.com
✅ Certbot will automatically configure SSL and modify your Nginx configuration.
5Verify Auto-Renewal
sudo certbot renew --dry-run
🎉 Your Nginx server is now secured with a free Let’s Encrypt SSL certificate!