Your SSL Cert Expired Again: Make It a One-Time Setup
An expired certificate is a process failure, not a memory failure. Here's how to make renewal automatic: certbot auto-renewal, reload hooks, expiry monitoring, plus the traps that bite anyway — CDN certs, incomplete chains and HSTS.
Every year a huge number of sites go down once over a certificate that only lasts 90 days. It isn't hard — nobody just made it a non-event.
Certificate expiry has three properties: it arrives with no warning, it affects every visitor, and fixing it takes minutes. The time worth spending is the hour before it first breaks, setting the process up once.
Why certs expire: three failure patterns
- Memory-based: whoever requested it remembers. People change; expiry dates don't care.
- Renewed but not applied: files updated, web server never reloaded, old cert still in the running process.
- Origin only: the CDN or load balancer still serves the old cert, and that's the one users see.
Step 1: issue with certbot and let it renew
Let's Encrypt certs are free and valid 90 days, and certbot ships with renewal built in. The point isn't issuing — it's making renewal happen on a schedule and actually take effect.
# Install
dnf install -y certbot python3-certbot-nginx # RHEL / Oracle Linux
apt install -y certbot python3-certbot-nginx # Debian / Ubuntu
# Issue via webroot (swap in your web root)
certbot certonly --webroot -w /data/www/example.com \
-d example.com -d www.example.com --agree-tos -m you@example.com
# Dry run first, so renewal never surprises you
certbot renew --dry-run
certbot installs a timer that checks daily and renews anything inside 30 days of expiry:
systemctl list-timers | grep certbot
systemctl status certbot-renew.timer
# Confirm renewal actually reloads the web server
cat /etc/letsencrypt/renewal/example.com.conf | grep -i hook
Step 2: always reload after renewal
The most common miss: files replaced, nginx never re-read them, browsers still get the old date. Make it automatic with a deploy hook:
certbot renew --deploy-hook 'systemctl reload nginx'
# Or bake it into the renewal config permanently
echo "deploy_hook = systemctl reload nginx" >> /etc/letsencrypt/renewal/example.com.conf
- reload, not restart: no dropped connections.
- Use fullchain.pem, not cert.pem: the latter omits the intermediate and some browsers call it insecure.
- Point nginx at both: ssl_certificate and ssl_certificate_key.
Step 3: add a monitor that shouts before it expires
Auto-renewal answers "it shouldn't expire"; monitoring answers "if it didn't". You need both — renewal fails silently when DNS moves, permissions change, or the webroot path is edited.
- Threshold alerts: 30 / 14 / 7 days remaining, not a single cutoff.
- Probe from outside: complete a real HTTPS handshake and read the served cert, don't read files on the box.
- Route alerts somewhere you'll see them: WeChat or email beats a log file nobody opens.
- Monitor each name separately, especially ones added later.
# Days remaining, by hand (swap the domain)
example=example.com
end=$(echo | openssl s_client -connect $example:443 -servername $example 2>/dev/null \
| openssl x509 -noout -enddate | cut -d= -f2)
echo "$example expires: $end ($(( ( $(date -d "$end" +%s) - $(date +%s) ) / 86400 )) days left)"
The traps that still bite
- CDN certs: managed CDN certs usually renew themselves, but if you uploaded your own, you own that expiry date too.
- Incomplete chain: desktop fine, phone warns — check the chain, fix it with fullchain.pem.
- HSTS on: once it is, a broken cert leaves users without even a "continue anyway" button. Don't enable HSTS until monitoring is in place.
- Multiple servers: renewed on one box only. Either distribute the cert centrally or renew and monitor on every box.
- Clock drift: skews every expiry calculation. Keep NTP in sync.
- Revocation and CA changes: occasionally you must reissue by hand, so keep a working reissue command in your runbook.
A checklist worth copying
- List every HTTPS layer (browser / CDN / origin) and each cert's expiry date.
- Get certbot renew --dry-run to pass clean.
- Add the deploy hook so renewal reloads automatically.
- Install expiry monitoring at 30/14/7 days, probing from outside.
- Serve fullchain.pem and verify once on a phone.
- Write the reissue command into your ops doc so anyone can run it.
If you'd rather not maintain any of this: managed ops from ¥80/month includes 30-day-ahead expiry alerts and renewal handled for you, with verification and a record afterwards. If it's already broken, a one-off remote diagnosis is ¥100 and starts by pinning down this exact layer.