A certificate expiring at midnight is the typical failure of a server whose automation was only half set up: Certbot renewed it but Nginx wasn’t reloaded, or a CDN rule never let the validation request reach the origin. Let’s Encrypt issues the certificate for free; the real work is tying the steps of obtaining, renewing and loading it into the service into a setup that runs without anyone having to remember. Below we cover choosing a validation method, renewal with Certbot and acme.sh, deploy hooks, pitfalls behind a CDN and monitoring renewal errors.
ACME validation methods
Let’s Encrypt receives certificate requests with the ACME protocol defined in RFC 8555. Before issuing a certificate, it requires the applicant to prove control of the domain; this is called a “challenge”. Let’s Encrypt supports three methods:
- HTTP-01: The client places specific content at
http://domain/.well-known/acme-challenge/<token>; Let’s Encrypt queries this address over port 80 from several network locations. - DNS-01: The client creates a TXT record with a specific value at
_acme-challenge.domain. - TLS-ALPN-01: Validation is done with a special TLS handshake on port 443. Certbot’s built-in plugins don’t support this method; it’s used mostly in server and proxy software that embeds ACME.
Let’s Encrypt certificates have long been valid for 90 days, and both Let’s Encrypt’s announced plans and CA/Browser Forum decisions show that certificate lifetimes will gradually shorten. As lifetimes shorten, manual renewal becomes unsustainable. A calendar reminder isn’t a method. Follow the current timeline in Let’s Encrypt announcements and set up automation to work independently of the lifetime.
Comparing HTTP-01 and DNS-01
| Criterion | HTTP-01 | DNS-01 |
|---|---|---|
Wildcard (*.example.com) |
Not supported | Supported |
| Port 80 access | Required | Not required |
| Internal server closed to the internet | Unusable | Usable |
| Permission needed | Write to the web root | Write to the DNS zone (API) |
| Multiple servers / load balancer | The request may land on another node | Independent of the number of servers |
| Security risk | Low | If the API key is compromised, the zone can be changed |
The practical decision: for a single-server, internet-facing corporate website, HTTP-01 is the simplest path. DNS-01 is preferred if a wildcard is needed, the server is closed to the internet, multiple nodes serve the same domain or there’s a CDN in front. With DNS-01, limit the API token to DNS edit permission on the relevant zone only; if your DNS provider doesn’t offer granular permissions, delegating the _acme-challenge record via CNAME to a separate zone used only for this job narrows the risk. The DNS token is the key to the domain. Let’s Encrypt’s method details are in the Challenge Types document.
Setup and renewal with Certbot
Certbot is the ACME client developed by the EFF, installable via distribution packages and snap. Three typical uses:
# 1) Nginx plugin: Certbot handles validation and server block editing
certbot --nginx -d example.com -d www.example.com
# 2) Webroot: HTTP-01 via the existing web root, without touching the configuration
certbot certonly --webroot -w /var/www/example.com/public -d example.com -d www.example.com
# 3) DNS-01 and wildcard (with the certbot-dns-cloudflare plugin)
certbot certonly --dns-cloudflare \
--dns-cloudflare-credentials /root/.secrets/cloudflare.ini \
-d example.com -d '*.example.com'
The Cloudflare credentials file is a single line (dns_cloudflare_api_token = …) and must be protected with chmod 600 so only root can read it; the token should be created in the Cloudflare panel with DNS edit permission for the relevant zone only. On manually managed servers, certonly is more predictable: the certificate path stays fixed, you write the server block yourself and Certbot doesn’t touch your configuration. In production you don’t want surprises.
The Certbot package sets up renewal: a systemd timer named certbot.timer for distribution package installs, or snap.certbot.renew.timer for snap installs, runs certbot renew twice a day. renew only processes certificates that are due for renewal. Right after setup, verify the following:
systemctl list-timers | grep -i certbot
certbot certificates # certificates, domains, expiry dates
certbot renew --dry-run # full renewal rehearsal in the staging environment
Each certificate’s renewal parameters (validation method, webroot path, hooks) are stored in /etc/letsencrypt/renewal/<name>.conf; renewal is done with the method used when first obtained. When experimenting, use Let’s Encrypt’s test environment with the --test-cert (--staging) option. Repeated failed attempts in production hit the rate limit and also block obtaining a real certificate for that domain for a while.
The acme.sh alternative
acme.sh, which runs as a shell script, supports many DNS providers and can be installed without root. An overlooked detail: acme.sh’s default certificate authority isn’t Let’s Encrypt; to use Let’s Encrypt, specify it explicitly.
acme.sh --set-default-ca --server letsencrypt
export CF_Token="..." # Cloudflare API token
acme.sh --issue --dns dns_cf -d example.com -d '*.example.com'
acme.sh --install-cert -d example.com \
--key-file /etc/nginx/ssl/example.com.key \
--fullchain-file /etc/nginx/ssl/example.com.fullchain.pem \
--reloadcmd "systemctl reload nginx"
The target paths and reload command defined with --install-cert are saved; on renewal, acme.sh’s own cron job copies the files to these paths and runs the command. Don’t point the web server directly at acme.sh’s internal directory.
Deploy hooks and reloading services
Renewal can succeed and the site still serves the old certificate. Nginx, Apache, Postfix or HAProxy load the certificate into memory and use the old one until they see a reload. In Certbot, a deploy hook is used for this. A deploy hook runs only when a certificate is actually renewed; it doesn’t run on every renew call.
#!/bin/sh
# /etc/letsencrypt/renewal-hooks/deploy/reload-services.sh (chmod 755)
set -e
nginx -t && systemctl reload nginx
# If other services also use the certificate:
case "$RENEWED_DOMAINS" in
*mail.example.com*) systemctl reload postfix ;;
esac
Certbot passes the RENEWED_LINEAGE (the certificate’s live directory) and RENEWED_DOMAINS (space-separated domains) environment variables to the hook. If a hook specific to a single certificate is needed, the --deploy-hook "systemctl reload nginx" parameter can be given when first obtaining it; this value is saved in that certificate’s renewal configuration.
If the certificate needs to be moved to another machine (a load balancer, a container, a Windows server), the copy is done inside the hook. In that case, access on the target system should be limited to a restricted user that can only write the certificate files, and the hook should return a non-zero exit code when the copy fails so the error shows up in the logs. A silent hook is a silent failure. In container-based deployments, how the certificate is attached to the reverse proxy container should be considered together with the structure in the Nginx reverse proxy configuration guide.
Validation behind a proxy or CDN
For HTTP-01 errors, Certbot is rarely to blame; the problem is usually a layer in the request’s path. The order of checks:
- Redirects: Let’s Encrypt follows redirects in HTTP-01, but only to ports 80 and 443 and the http/https schemes. A redirect rule going to another port or domain breaks validation.
- IPv6: If the domain has an AAAA record, Let’s Encrypt tries validation over IPv6 first. If the AAAA record points to an old server or the web server responds with the wrong site on IPv6, validation can fail; either fix the AAAA record or remove it.
- CDN and WAF: Bot protection, country blocks, “under attack” modes or rules that cache the
/.well-known/path keep the validation request from reaching the origin. Define an exception for this path or switch to DNS-01. - Multi-node setup: The load balancer can send the validation request to a node that didn’t request the certificate. Use a shared webroot, a rule that routes the
/.well-known/acme-challenge/path to a single node, or DNS-01. - CAA record: If the domain has a CAA record, it must contain an
issuepermission (issuewildfor wildcards) forletsencrypt.org.
Specifically with Cloudflare, since Cloudflare already serves the certificate to visitors, the job of the certificate on the origin server is to protect the connection between the CDN and the origin. Here Cloudflare’s origin certificate (Origin CA) can also be used instead of Let’s Encrypt; but that certificate is trusted only by Cloudflare, and browsers show an error when the proxy is turned off. For the caching side of the Cloudflare layer, see the Cloudflare, WP Rocket and Redis article.
Monitoring renewal errors
Automation breaks silently. In 2025 Let’s Encrypt ended its expiry warning emails; you now have to generate the warning yourself. Set up monitoring in two layers:
- From the inside: Monitor that the timer runs and doesn’t error.
journalctl -u certbot.service(snap.certbot.renew.servicewith snap) and/var/log/letsencrypt/letsencrypt.logshow the latest renewal attempts. In systemd, a unit that sends a notification on a failed run can be defined withOnFailure=. - From the outside: What really matters is the expiry date of the certificate being served. Check the certificate served over the network, not the one in the file; that way situations such as a forgotten reload or a CDN serving the old certificate are caught too.
#!/bin/sh
# Example: warn if the served certificate has less than 14 days left
HOST=www.example.com
if ! echo | openssl s_client -connect "$HOST:443" -servername "$HOST" 2>/dev/null \
| openssl x509 -noout -checkend $((14*86400)); then
echo "WARNING: $HOST certificate expires within 14 days" | logger -t cert-check
fi
If this check is connected to a monitoring system (an uptime service, Zabbix, Prometheus blackbox exporter, etc.), it gives visibility for all domains from a single screen. Choose a threshold wide enough to let automatic renewal be retried several times; when the warning comes, you still have time to fix the problem. A warning that arrives on the last day is too late.
The first places to look on a renewal error:
| Symptom | Likely cause |
|---|---|
| 404 during validation | The webroot path has changed, or the server block routes the /.well-known/ path elsewhere |
| Timeout during validation | Port 80 is closed in the firewall or the AAAA record is wrong |
| Record not found with DNS-01 | The API token has expired, its permissions have been narrowed or the propagation time is insufficient |
| Renewed but the old certificate is served | No deploy hook, or it failed |
| Rate limit error | Repeated use of the production environment during testing |
In setups that host many domains on a single server, certificate management can also be run through a panel; this scenario is covered in the article on multi-site server management with Virtualmin. Which protocols and ciphers the obtained certificate is served with is the subject of the TLS configuration guide. To set up certificates, backups and monitoring together on the server side, see our Linux VPS and hosting management service; all Certbot options are in the Certbot documentation.
Frequently asked questions
Can I use HTTP-01 for a wildcard certificate?
No. Let’s Encrypt issues wildcard certificates only with DNS-01 validation. For this, your ACME client must be able to create a TXT record through your DNS provider’s API, or the _acme-challenge record must be delegated via CNAME to a zone suitable for automation.
Does running certbot renew every day renew the certificate every day?
No. renew only processes certificates that are due for renewal and skips the rest. That’s why it runs twice a day: if there’s a temporary error, it’s retried on the next run.
The certificate was renewed but the site still shows the old one. Why?
The web server loads the certificate into memory at startup; even if the file changes, it doesn’t serve the new certificate until it’s reloaded. Run systemctl reload nginx or apache2 after renewal with a deploy hook. If other services copy the certificate file (a mail server, a container, a load balancer), add them to the hook too.
Can a Let’s Encrypt certificate be obtained while the Cloudflare proxy is on?
Yes. If the HTTP-01 request reaches the origin through Cloudflare, validation works; but WAF, bot protection or redirect rules may block the /.well-known/acme-challenge/ path. The least troublesome method is to use DNS-01 with a Cloudflare API token that has DNS edit permission only on the relevant zone.