How to Renew Let’s Encrypt Certificates Automatically and Avoid Expiry Downtime
A Let’s Encrypt certificate lasts 90 days, so renewal is not a yearly task you can forget. It is a background job that must work every two to three months, and an expiry means browsers block your site until you fix it. This guide shows how to renew Let’s Encrypt certificates automatically, prove the automation works with a dry run, and fix the failures that cause most expiries.
The good news is that Certbot sets up automation when you install it. The bad news is that many servers lose that automation later: a firewall rule changes, a web root moves, a plugin breaks after an upgrade, and nobody notices until the certificate expires. The fix is not more reminders. It is a tested renewal path plus a check that tells you about a failure while there is still time to act. If you have not issued a certificate yet, start with our guide to installing WordPress on a LEMP stack, which sets up the Nginx base first, then return here to lock renewal down.
Renew Let’s Encrypt Certificates Automatically with the Built-in Timer
Certbot installs a systemd timer that runs certbot renew twice a day. That certbot timer systemd unit is the automation to verify first when renewal stops working. The command checks every certificate, renews only those within 30 days of expiry, and reloads the web server through a hook when a certificate changes. Check that the timer exists and is active:
systemctl list-timers | grep certbotsystemctl status certbot.timer
If the timer is missing, your install route may have skipped it. Create the habit another way: add a cron entry that runs certbot renew --quiet twice daily, or install the timer unit from the Certbot package for your system. Running renewal twice a day matters because it gives a failed attempt many retries before expiry, and each retry is a chance for a temporary outage, such as a DNS blip, to clear on its own.
Confirm which certificates the timer covers with sudo certbot certificates. That list shows each name, its expiry date, and its certificate path. A certificate missing from that list is not managed by Certbot at all, and no timer will renew it. Certificates issued by hand with other tools, or copied from another server, need their own renewal path or a fresh Certbot issue.
Test Renewal with a Certbot Renew Dry Run
A dry run uses the staging server and changes nothing, so it is safe to run any time:
sudo certbot renew --dry-run
Read the result per certificate, not just the final line. A run that passes for one domain and fails for another still leaves you with an expiry on the failing name. The dry run tests the same validation path the real renewal uses: HTTP challenges need port 80 open and the right web root, and DNS challenges need a working provider credential. For wildcard names that use DNS, the plugin setup the dry run will exercise is covered by the DNS plugin docs for your provider, and outside monitoring from our UptimeRobot vs Better Uptime vs HetrixTools comparison adds a second pair of eyes.
Run the dry run after every change that could touch validation: a firewall change, a server block edit, a DNS provider move, or a system upgrade. A two-minute test after a change beats a midnight expiry three months later, because the cause is still fresh in your mind when the test fails.
Hooks That Reload Services After Renewal
Renewal writes new files, but a running Nginx or app server keeps serving the old certificate from memory until it reloads. Certbot handles this with deploy hooks. The Nginx plugin reloads Nginx itself, but other services need a hook. Add one with:
sudo certbot renew --deploy-hook "systemctl reload nginx"
For a lasting setup, place a script in /etc/letsencrypt/renewal-hooks/deploy/ and make it executable. A deploy hook runs only when a certificate actually renews, not on every timer run, so it is safe to leave in place. Test the hook by running certbot renew --force-renewal once on a test name if you can afford the rate limit cost, or by checking the hook logic by hand. A renewal that writes files but never reloads the server looks successful in the log while visitors still see the old certificate, so this step deserves the same attention as the challenge itself.
SSL Certificate Expiry Monitoring as a Second Layer
Automation should not be your only guard. Add an outside check that watches the live certificate, because it catches the cases automation misses: a hook that failed, a server that never reloaded, or a certificate served from the wrong virtual host. Options include a monitoring service that alerts on expiry, a simple script that checks the date with openssl, or a status page that tracks the domain.
A minimal check you can run by hand or from cron looks like this:
echo | openssl s_client -connect yourdomain.com:443 -servername yourdomain.com 2>/dev/null | openssl x509 -noout -dates
Set the alert threshold at 20 days, not at 2. Twenty days leaves time to fix a broken challenge, wait out a rate limit, or move a DNS record. Two days leaves time to panic. Uptime monitoring pairs well here, and our Uptime Kuma setup guide shows a self-hosted monitor that can watch the site from outside the server itself.
Common Renewal Failures and Their Fixes
Port 80 closed is the most common HTTP failure. The challenge needs HTTP even when your site redirects everything to HTTPS, so the firewall must allow port 80 and Nginx must still answer the challenge path. Check with sudo ufw status and curl -I http://yourdomain.com/.well-known/acme-challenge/test to see what a validator would meet.
A changed web root breaks the webroot plugin, because Certbot writes the challenge file to the old folder while Nginx serves the new one. Update the renewal config under /etc/letsencrypt/renewal/ or reissue with the correct root. A DNS plugin failure usually means a revoked token or a moved zone; the log at /var/log/letsencrypt/letsencrypt.log names the failing step. Rate limit errors mean too many requests in a window, so fix the cause, wait, and use the staging server for further tests instead of burning the production allowance.
What to Do When a Certificate Already Expired
An expired certificate does not need a special recovery process. Fix the cause of the failed renewal first, then run sudo certbot renew and reload the web server. The new certificate replaces the expired one at once, and visitors see a valid site again after the reload. If renewal keeps failing, issue a fresh certificate with the original command and the same domain list, which replaces the old lineage cleanly.
While you fix it, do not work around the problem by disabling HTTPS or telling visitors to click past the warning. Both teach visitors to ignore the exact warning that protects them, and search engines treat a broken HTTPS site as a broken site. A short outage with a clean fix is better than a workaround that lingers. After recovery, run the dry run, set the 20-day monitor, and note what broke so the next renewal does not fail for the same reason. For Docker-based services, the same renewal discipline applies, and our guide to free SSL for Docker apps shows how renewal hooks fit a container setup.