To set up Nginx with Let's Encrypt for automatic SSL certificate renewal, follow these steps:
Install the Certbot tool:
sudo apt-get install certbot
sudo yum install certbot
sudo pkg install certbot
Generate the initial SSL certificate using Certbot:
sudo certbot certonly --nginx -d example.com -d www.example.com
example.com
with your own domain name(s)Configure Nginx to use the SSL certificate:
sudo nano /etc/nginx/sites-available/example.com
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
Note: Replace example.com
with your own domain nameTest the Nginx configuration and restart Nginx:
sudo nginx -t
sudo systemctl restart nginx
Set up automatic certificate renewal using a cron job:
sudo crontab -e
0 0,12 * * * certbot renew --post-hook "systemctl reload nginx"
Verify automatic renewal:
sudo certbot renew --dry-run
That's it! Your Nginx server is now set up with Let's Encrypt SSL certificate and automatic renewal.