Chapter 5 · Lesson 6 of 10
Fix it

Fix Let's Encrypt certificate errors

Let's Encrypt errors come from a failed domain check, usually DNS pointing elsewhere, port 80 blocked or a broken renewal timer, so check each before you retry.

By the end you will

Find why a Let's Encrypt certificate was not issued or renewed, fix the DNS, port or timer, and confirm it with a dry run.

Time
20 min
Level
Intermediate
Check
4 questions
You need
  • A domain you control and a server with certbot
  • SSH access with sudo

Certbot prints Challenge failed for domain app.example.com, the browser shows an expired certificate warning, or the log says you hit a rate limit. In every case the authority could not confirm that you control the domain at that moment, or your server stopped renewing. Work through DNS, port 80, the proxy in front, CAA records and the renewal timer, in that order.

How it works#

Let’s Encrypt issues a certificate only after your server proves control of the domain through the ACME protocol. With the common HTTP-01 challenge, the authority gives certbot a token, certbot serves it at http://app.example.com/.well-known/acme-challenge/<token>, and the authority fetches that URL from the internet over port 80. If anything between the authority and certbot breaks, the check fails. Certificates last 90 days, so renewals must also work unattended. The challenge types are described in the Let’s Encrypt docs.

Step 1: Read the exact error#

bash
sudo certbot certificates
sudo tail -n 60 /var/log/letsencrypt/letsencrypt.log

The first lists each certificate and its expiry. The second holds the detailed failure. Typical messages are Timeout during connect (likely firewall problem), Connection refused, NXDOMAIN looking up A for ..., and Invalid response ... 404. Each points at a different step below.

Step 2: Check that DNS points at this server#

bash
dig +short app.example.com A
dig +short app.example.com AAAA
curl -s https://ifconfig.me

The A record must match the public IP of the server running certbot, for example 203.0.113.10. A stale AAAA record is a frequent trap: Let’s Encrypt prefers IPv6 when it exists, so a wrong AAAA record fails the check even when the A record is right. Remove or fix it. If the name does not resolve at all, see fix a domain that does not resolve. For DNS basics, see check DNS with dig.

Step 3: Check that port 80 reaches the right process#

From another machine:

bash
curl -v http://app.example.com/.well-known/acme-challenge/test

You expect an HTTP answer, even a 404. A timeout points at a firewall: open port 80 in ufw and in your provider’s firewall. A refusal means nothing listens on port 80. If a web server already uses it, certbot’s --standalone mode cannot bind it, so use the webroot or nginx plugin instead, or stop the server briefly. Also check that your HTTP-to-HTTPS redirect does not send /.well-known/acme-challenge/ to a page that fails. Redirecting to HTTPS on the same host is accepted, but a redirect loop is not. See redirect HTTP to HTTPS explained.

Step 4: Check CAA records#

bash
dig +short CAA example.com

No output means no restriction. If records exist, one must allow letsencrypt.org, for example 0 issue "letsencrypt.org". CAA is inherited from the parent domain, so a record on example.com applies to app.example.com unless the subdomain has its own. Fix it at your DNS provider.

Step 5: Look at rate limits#

If the error mentions a rate limit, wait. Let’s Encrypt limits certificates per registered domain, duplicate certificates and failed validations over time windows. The exact numbers are published on the rate limits page and can change, so read it there instead of trusting a number from memory. To avoid burning limits while you debug, use the staging environment:

bash
sudo certbot certonly --staging -d app.example.com

Staging certificates are not trusted by browsers. Once staging succeeds, run the real command once.

Step 6: Fix expired certificates and the renewal timer#

If the certificate already expired, renewal did not run. On most systems certbot installs a systemd timer:

bash
systemctl list-timers | grep certbot
sudo systemctl status certbot.timer

If the timer is missing or inactive, enable it with sudo systemctl enable --now certbot.timer. Some installs use a cron entry in /etc/cron.d/certbot instead. Then run the real renewal:

bash
sudo certbot renew

Renewal reuses the settings saved in /etc/letsencrypt/renewal/app.example.com.conf. If you issued with --standalone and later started a server on port 80, renewal now fails for the same port clash. Switch the authenticator in that file or reissue with the nginx plugin. A web server must be reloaded to use a new file, so a deploy hook such as --deploy-hook "systemctl reload nginx" matters. See renew Let’s Encrypt certificates.

Check it worked#

bash
sudo certbot renew --dry-run
echo | openssl s_client -connect app.example.com:443 -servername app.example.com 2>/dev/null | openssl x509 -noout -dates

The dry run should end with Congratulations, all simulated renewals succeeded. The notAfter date should be about 90 days ahead.

Prevent it#

  • Run certbot renew --dry-run after every change to the web server, firewall or DNS.
  • Monitor the certificate expiry date from outside, so you hear about it before visitors do.
  • Keep the AAAA record correct or absent.

Edge cases and gotchas#

  • Cloudflare or another proxy in front: The authority reaches the proxy, not your server. Pause the proxy or use the DNS challenge.
  • Wildcards: They need the DNS-01 challenge, not HTTP-01.
  • New domain too fresh: Records need time to reach the authority’s resolvers. Check with dig @1.1.1.1.
  • Several servers behind one name: The check may hit a server without the token. Make challenge answers reach the same host.
  • Docker proxies: If a container publishes port 80, certbot on the host cannot bind it. Stop it briefly or use webroot.
  • Clock drift: A server clock far off makes TLS checks fail oddly. Keep time sync on.

Troubleshooting#

SymptomLikely causeFix
Timeout during connectPort 80 blockedOpen port 80 in ufw and the provider firewall
NXDOMAIN looking up ARecord missing or wrong nameAdd the A record, wait for DNS
Invalid response, 404 or wrong contentAnother server or app answers on port 80Route the challenge path to certbot’s webroot
Fails only for IPv6Wrong AAAA recordFix or remove the AAAA record
CAA record prevents issuanceCAA lists another authorityAdd 0 issue "letsencrypt.org"
Too many failed validations or certificatesRate limitWait, use --staging while debugging
Certificate expired, renew never ranTimer disabledEnable certbot.timer, run certbot renew

Quick reference#

bash
sudo certbot certificates
sudo tail -n 60 /var/log/letsencrypt/letsencrypt.log
dig +short app.example.com A
dig +short CAA example.com
sudo certbot renew --dry-run
systemctl list-timers | grep certbot

Next#

Continue with Fix a domain that does not resolve.

Check what you learned4 questions
1For the HTTP-01 challenge, which port must be reachable from the internet?
2certbot reports a timeout during connect for your domain. What do you check first?
3How do you safely test the renewal setup?
4What can a CAA record on your domain do?

Frequently asked questions

Why did Let's Encrypt fail to issue my certificate?

The authority could not prove you control the domain. The usual reasons are that the domain points at a different server, port 80 is blocked, a proxy answers instead of certbot, or a CAA record forbids the issuer.

Why is my Let's Encrypt certificate expired?

Automatic renewal did not run or failed. Check the certbot timer with systemctl list-timers and test with certbot renew --dry-run.

What is the Let's Encrypt rate limit?

Let's Encrypt limits how many certificates and failed validations a domain can have in a time window. The exact numbers are on their rate limits page and can change, so test with the staging environment to avoid hitting them.

How do I test certificate renewal without issuing a real one?

Run sudo certbot renew --dry-run. It uses the staging environment, so it checks the whole renewal path without counting against production limits.

Sources

View MD Edit
Share
Helpful?
Progress is saved in this browser only.

Keep going: guides and tutorials

View MD Edit
Share
Helpful?
Run this on your own server

Levelrail deploys apps from git with health-checked releases and one-click rollback.

docker pull ghcr.io/glincker/levelrail:latest Install Levelrail From GLINR Studios