Operations 7 min read

Certbot Renewal Failed on Ubuntu? How to Fix It

The first sign of a failed Certbot renewal is usually a browser warning. The reason is already written down in a log, and reading it beats guessing.

By BashPilot Team
BashPilot AI server management One request plans, executes and verifies the fix, on every server. See pricing

When Certbot renewal fails on an Ubuntu server, you usually find out from a browser warning, because the scheduled job that should have renewed the certificate failed quietly weeks earlier. The reassuring part is that Certbot records exactly why it failed. The work is reading that reason instead of guessing at firewalls.

Read the actual error first

Start with a dry run. It exercises the same code path as a real renewal, including the authenticator saved for each certificate, without touching your live files.

run a safe test renewal
sudo certbot renew --dry-run

Certbot keeps its status logs in /var/log/letsencrypt. The newest entries contain the full error from Let's Encrypt, which is more detailed than what the dry run prints.

read the end of the log and list what Certbot manages
sudo tail -n 80 /var/log/letsencrypt/letsencrypt.log
sudo certbot certificates

certbot certificates lists every certificate by name with its domains and expiry date. Compare that list with the sites you actually serve, because a certificate that was issued once by hand and never added to a renewal configuration will not appear.

Message in the logUsually means
Timeout during connect (likely firewall problem)Port 80 is not reachable from the internet, or the domain points at another machine
Connection refusedNothing is listening on port 80 at that address, or the web server is down
Invalid response ... 404 for the acme-challenge URLThe web server answers but is not serving the challenge file from the folder Certbot wrote it to
DNS problem: NXDOMAIN looking up A for ...A hostname in the certificate no longer exists in DNS, often an old www or subdomain

Check that renewal is scheduled at all

Certbot's documentation says automatic renewal is normally pre-configured as a scheduled task running certbot renew, either a cron entry or a systemd timer. See which one your server has.

find the timer and the Certbot binary in use
systemctl list-timers 'certbot*' 'snap.certbot*'
which -a certbot

On Ubuntu it is common to find two copies of Certbot, one from apt and one from the snap, both pointing at the same /etc/letsencrypt directory. Pick one and remove the other, because two installs with two timers make every failure harder to read. The snap's timer is named snap.certbot.renew.timer.

Fix the usual challenge failures

Most failures come from the HTTP-01 challenge, where Let's Encrypt fetches a token file from http://your-domain/.well-known/acme-challenge/ over port 80. Work through these in order.

  1. 1

    Is port 80 open and answered by nginx?

    sudo ss -ltnp | grep ':80 ' shows what is listening, and sudo ufw status shows whether the firewall allows it. Test from another machine, not from the server itself, because a local request proves nothing about the internet path.

  2. 2

    Does DNS point at this server, over IPv4 and IPv6?

    Run dig +short A example.com and dig +short AAAA example.com. A stale AAAA record is a classic cause, since the validation request may go to an IPv6 address that no longer leads to this server.

  3. 3

    Does the saved renewal configuration use the right authenticator?

    Each certificate has a file at /etc/letsencrypt/renewal/NAME.conf. If its authenticator is standalone, Certbot wants port 80 for itself, which fails whenever nginx is already running.

  4. 4

    Is a rule in nginx blocking the challenge path?

    A catch-all redirect to another host, or a dotfile rule such as location ~ /\. { deny all; }, will stop Let's Encrypt from reading .well-known. Add an explicit exception for the challenge path above those rules.

  5. 5

    Are you hitting the failure limit?

    After five failed validations in an hour for the same hostname, Let's Encrypt refuses new orders until the allowance refills. Debug with --dry-run only, then run one real renewal when the dry run passes.

see which authenticator and webroot a certificate uses
sudo grep -E 'authenticator|installer|webroot' /etc/letsencrypt/renewal/example.com.conf
let nginx serve the challenge path ahead of any deny or redirect rule
location ^~ /.well-known/acme-challenge/ {
    root /var/www/example;
    default_type text/plain;
}

If the authenticator is wrong, re-issue the settings with the method you actually want. Certbot saves the options you used for each certificate, so running it once with the correct plugin replaces the old ones. Back up the renewal file first, because Certbot's own documentation warns that hand-editing these files can damage them.

switch an existing certificate to the webroot authenticator
sudo cp /etc/letsencrypt/renewal/example.com.conf /root/example.com.conf.bak
sudo certbot certonly --webroot -w /var/www/example -d example.com -d www.example.com --cert-name example.com
sudo certbot renew --dry-run

Make nginx load the new certificate

Certbot can renew successfully and your visitors still see the old certificate, because nginx keeps the previous one in memory until it reloads. Certbot runs executable scripts from /etc/letsencrypt/renewal-hooks/deploy only after a successful renewal, which makes that directory the right place for a reload.

create a deploy hook that reloads nginx
sudo tee /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh >/dev/null <<'EOF'
#!/bin/sh
systemctl reload nginx
EOF
sudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh

One detail catches people during testing: a dry run does not run deploy hooks unless you add --run-deploy-hooks. A hook that looks untested after a dry run has not necessarily failed.

Checking each server's timer, renewal file and served certificate by hand is quick once and tedious across a fleet. BashPilot can run those checks as one request on every Ubuntu server you manage. It reads the renewal log, timers and certificate expiry first, asks for approval before it changes renewal settings or reloads a service, and checks the result afterwards. The related disk and CPU checks in Why Is My Linux Server CPU at 100%? follow the same read-first approach.

In BashPilot

Checking certificate renewal on two servers

app.bashpilot.com
check certificate expiry and renewal setup on web01 and web02
BashPilot

Read-only check done. web01 is healthy. On web02 the certificate has 11 days left, and its renewal file uses the standalone authenticator while nginx is running on port 80, which will fail.

ServerDays leftTimerAuthenticator
web0152activewebroot
web0211activestandalone
fix web02 to use webroot
BashPilot

This changes the renewal settings for example.com on web02. Confirm and I will run it, then do a dry run to prove the renewal works.

bash
certbot certonly --webroot -w /var/www/example -d example.com --cert-name example.com
certbot renew --dry-run
Example output, not a screenshot of a specific customer's server.

Try this on one of your own servers.

Start free trial

Prove the fix worked

  • sudo certbot renew --dry-run finishes with every certificate listed as a success.
  • systemctl list-timers 'certbot*' 'snap.certbot*' shows a next run time in the near future.
  • After the next real renewal, sudo certbot certificates shows a new expiry date, and the certificate nginx serves matches it.
see the certificate visitors actually receive
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates

Stop it failing silently again

Renewal depends on a timer, a reachable port, a correct authenticator and a reload. Any one of them can break months after you set it up. Add a check that does not depend on Certbot at all, so a silent failure becomes a visible one.

exit non-zero if a certificate expires within 14 days
openssl x509 -checkend 1209600 -noout -in /etc/letsencrypt/live/example.com/fullchain.pem

Run that from cron or your monitoring system and alert on a non-zero exit. Then the next failed renewal reaches you two weeks before visitors see a warning, instead of the morning someone reports the site as insecure.

Share LinkedIn X
Questions

Frequently asked questions

Why does certbot renew --dry-run pass but the real renewal fails?

A dry run uses Let's Encrypt's staging server, so it can pass while the production run fails on a rate limit or a recent DNS or firewall change. It also skips deploy hooks unless you pass `--run-deploy-hooks`, and a scheduled job may run with a different environment than your shell. Read `/var/log/letsencrypt/letsencrypt.log` for the real production error.

How often does Certbot renew certificates?

The scheduled task normally runs twice a day, but a certificate is only renewed once less than a third of its lifetime remains, about 30 days for a 90 day certificate. Before Certbot 4.0.0 the threshold was a fixed 30 days. A certificate with plenty of time left is simply skipped.

How many failed attempts before Let's Encrypt blocks me?

Up to five authorization failures per identifier can be incurred by one account every hour, and the allowance refills at one per identifier every 12 minutes. When it runs out you cannot place new orders for that hostname until it refills, so debug with `--dry-run` instead of repeating real attempts.

Do I need to restart nginx after Certbot renews a certificate?

A reload is needed for nginx to serve the new certificate, and Certbot only does it for you when an installer plugin handles it. Put `systemctl reload nginx` in an executable script under `/etc/letsencrypt/renewal-hooks/deploy`, which runs only after a successful renewal.

Is it safe to delete /etc/letsencrypt and start again?

No. The `live` folder contains symlinks into `archive`, and each certificate has a renewal file tying them together, so deleting pieces by hand leaves a broken setup. Use `sudo certbot delete --cert-name example.com` to remove one certificate cleanly, then request it again.

Put your servers on autopilot.

Connect a server in about a minute. The first week is on us.