Requirements
- DNS points to the server: A and, if present, AAAA record. Let's Encrypt prefers IPv6; a wrong AAAA record makes validation fail. Check in the DNS lookup.
- Port 80 is reachable and there is a
serverblock with all names inserver_name.
Install certbot
# Debian, Ubuntu sudo apt install certbot python3-certbot-nginx # RHEL, Rocky, Alma (from EPEL) sudo dnf install epel-release sudo dnf install certbot python3-certbot-nginx # alternative, always up to date sudo snap install --classic certbot
Option 1: certbot configures nginx
sudo certbot --nginx -d example.com -d www.example.com
certbot finds the matching server block, adds listen 443 ssl, certificate and key (marked # managed by Certbot) and the HTTP redirect if you want. The TLS settings come from /etc/letsencrypt/options-ssl-nginx.conf. On renewal certbot reloads nginx itself.
Option 2: webroot, configuration in your hands
If you maintain the nginx configuration yourself, e.g. with Ansible or following the article set up SSL/TLS in nginx, let certbot only obtain the certificate. The port 80 block needs a fixed place for the challenge files:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
location /.well-known/acme-challenge/ { root /var/www/letsencrypt; }
location / { return 301 https://$host$request_uri; }
}
sudo mkdir -p /var/www/letsencrypt sudo certbot certonly --webroot -w /var/www/letsencrypt -d example.com -d www.example.com \ --deploy-hook "systemctl reload nginx"
In the HTTPS block, then ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; and ssl_certificate_key …/privkey.pem;. The deploy hook is stored in the renewal configuration and runs at every renewal.
Automatic renewal
The packages’ systemd timer checks twice a day and renews from 30 days remaining:
systemctl list-timers | grep certbot sudo certbot renew --dry-run
Without a reload nginx keeps serving the old certificate until it expires. That is the most common cause of ERR_CERT_DATE_INVALID despite working renewal. Let's Encrypt has not sent reminder emails since 2025, so add the server to the certificate expiry overview.
Wildcard and internal servers
For *.example.com and for servers not reachable from the internet, use DNS validation (DNS-01) with a plugin for your DNS provider or acme.sh. The ACME helper generates the commands.
Typical errors
Timeout during connect: port 80 is blocked (firewall, host, router).Invalid response … 404: the challenge file is not where nginx looks. Usually thelocationblock is missing, or anotherserverblock answers because the name is not inserver_name.Could not automatically find a matching server block: certbot finds no block with the name. Add it toserver_name, runnginx -t, reload.CAA record … prevents issuance: allowletsencrypt.orgin the CAA record and check with CAA & DANE.- Rate limit: at most 5 identical certificates per week. Use
--test-certfor experiments.
Then check chain and protocols with the SSL check; for HTTP/3 see the article enable HTTP/3 in nginx.
FAQ
Plugin or webroot – which is better?
The plugin is quicker to set up. Webroot is better if you manage the configuration yourself or roll it out automatically, because certbot then changes nothing in nginx.
Does this work with nginx in a Docker container?
Yes, with webroot: mount the challenge directory and /etc/letsencrypt as volumes and reload the container in the deploy hook (docker exec … nginx -s reload).
Do I need OCSP stapling?
No. Let's Encrypt shut down OCSP in 2025; ssl_stapling no longer does anything for these certificates.