To secure communication between clients and the server using HTTPS, obtaining free certificates from Let's Encrypt and automating renewal.
- Any public-facing web service.
- Compliance requirements (PCI-DSS).
Install the necessary packages for your OS (Ubuntu/Debian example).
sudo apt update
sudo apt install certbot python3-certbot-nginxRun Certbot to automatically fetch the certificate and configure Nginx.
# Request certificate for a single domain
sudo certbot --nginx -d example.com -d www.example.com
# Follow the prompts:
# 1. Enter email for renewal notifications
# 2. Agree to Terms of Service
# 3. Choose whether to redirect HTTP to HTTPS (Recommended: Yes)If you are using a wildcard certificate or don't have port 80 open.
sudo certbot certonly --manual --preferred-challenges dns -d "*.example.com" -d "example.com"
# You will need to add a TXT record to your DNS provider as instructedCertbot usually adds a systemd timer or cron job automatically.
# Test the renewal process without making changes
sudo certbot renew --dry-run
# Check systemd timer status
systemctl status certbot.timerEnsure the generated configuration in /etc/nginx/sites-available/ looks correct.
server {
listen 443 ssl; # managed by Certbot
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}- Domain Resolution: The domain must point to the server's public IP before running Certbot.
- Port 80: Must be open and not used by another process (unless using the
--nginxplugin which handles this). - Rate Limits: Let's Encrypt has strict limits (e.g., 50 certificates per registered domain per week).
- Security: Protect the
/etc/letsencrypt/directory; it contains your private keys.
A secured website with a valid, auto-renewing SSL certificate.