Sub topic 14
Verifying the certificate and renewal
Getting a certificate is only half the job. This chapter covers how to confirm that nginx serves the right certificate, that the chain is complete, and that renewal will work without you. It assumes you have already obtained a certificate with Certbot, configured nginx for TLS, and know how systemd timers work.
What you are verifying
A working HTTPS site depends on several separate facts. Each one can fail on its own, so check them separately.
- The server presents the certificate you expect, for the name the client asked for.
- The certificate has not expired and has a sensible remaining lifetime.
- The server sends the intermediate certificates along with the leaf, so clients can build the chain.
- The negotiated protocol version is one you allow.
- A scheduled renewal job exists and can complete.
- nginx loads the renewed certificate after each renewal.
Step 1: Check what Certbot has on disk
Start with the files, because they show what Certbot believes is installed.
sudo ls -l /etc/letsencrypt/live/example.com/
sudo certbot certificatesThe ls -l output shows that fullchain.pem and privkey.pem are symlinks into /etc/letsencrypt/archive/example.com/. Each renewal writes new numbered files (fullchain2.pem, fullchain3.pem, and so on) and moves the symlinks. Your nginx configuration should point at the live/ paths, never at archive/, so it follows the symlinks automatically.
certbot certificates lists each certificate name, its domains, its expiry date, and the file paths. Look at three things:
- The domain list includes every name you serve, such as both
example.comandwww.example.com. - The line
VALID: N daysshows the time left. A freshly issued Let's Encrypt certificate is valid for 90 days. - A staging certificate is labeled as a test certificate (
INVALID: TEST_CERT). If you see that on a production site, you issued from staging by mistake and must request a real certificate.
Step 2: Check what the server actually serves
The files on disk are not proof. nginx keeps the certificate it loaded at startup or at the last reload. Ask the running server directly.
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
| openssl x509 -noout -subject -issuer -datesThe pieces of this command do the following:
echo |sends an empty line sos_clientcloses the connection instead of waiting for input.-servername example.comsends the SNI (Server Name Indication) value. Without it, a server hosting several sites may return its default certificate, and you would verify the wrong site.2>/dev/nullhides the connection log.openssl x509 -noout -subject -issuer -datesprints only the fields you need.
Typical output looks like this:
subject=CN = example.com
issuer=C = US, O = Let's Encrypt, CN = R11
notBefore=Nov 20 02:10:00 2026 GMT
notAfter=Feb 18 02:09:59 2027 GMTCompare notAfter with the date reported by certbot certificates. If the server shows an older date than the disk, nginx has not reloaded since the last renewal. That is the most common real-world failure, and it is why the deploy hook in a later step matters.
Check the names the certificate covers
The subject alone can hide extra names. Print the Subject Alternative Names, which are what browsers actually match against.
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
| openssl x509 -noout -ext subjectAltNameEvery hostname you serve must appear in this list. Modern clients ignore the Common Name and use only the Subject Alternative Names.
Step 3: Check the chain and the protocol version
A browser may hide a missing intermediate certificate, because it caches intermediates or fetches them itself. Command-line clients, mobile apps and API consumers often do not. Test with a strict client.
echo | openssl s_client -connect example.com:443 -servername example.com -showcerts 2>/dev/null \
| grep -E 'Verify return code|s:|i:|Protocol|Cipher'Read the result as follows:
Verify return code: 0 (ok)means openssl built a trusted chain from what the server sent.- Two or more
s:/i:pairs mean the server sent the leaf and at least one intermediate. If you see only one pair and an error such as code 21 (unable to verify the first certificate), nginx is servingcert.peminstead offullchain.pem.
Next, confirm which protocol versions the server accepts. The configuration in this tutorial allows only TLS 1.2 and 1.3, so older versions must fail.
echo | openssl s_client -connect example.com:443 -servername example.com -tls1_3 2>&1 | grep -E 'Protocol|Cipher'
echo | openssl s_client -connect example.com:443 -servername example.com -tls1_1 2>&1 | grep -iE 'alert|error|Protocol'The first command should report TLSv1.3. The second should fail with a handshake error. Some distributions build openssl without TLS 1.1 support, in which case the client itself refuses, and the test proves nothing. In that case use an external scanner or nmap --script ssl-enum-ciphers -p 443 example.com.
Step 4: Confirm the redirect and HSTS header
Check the HTTP behavior with curl.
curl -sI http://example.com/ | head -n 5
curl -sI https://example.com/ | grep -i strict-transport-securityThe first request should return 301 with a Location: header that begins with https://. The second should print the Strict-Transport-Security header. HSTS tells browsers to refuse plain HTTP for the stated time, so confirm the redirect works before you rely on it.
Step 5: Confirm that renewal is scheduled
Certbot does not renew by itself. Something must run certbot renew regularly. The Debian and Ubuntu packages install a systemd timer, and some older setups use a cron entry.
systemctl list-timers | grep -i certbotYou should see a timer such as certbot.timer with a next run time and the last run time. If nothing appears, check for a cron job:
cat /etc/cron.d/certbotIf neither exists, for example because you installed Certbot from a different source, you must create a timer or cron job yourself. The certbot renew command only renews certificates that are within 30 days of expiry, so running it twice a day is cheap and safe.
Step 6: Simulate a renewal
A dry run exercises the full renewal path without changing your live certificate.
sudo certbot renew --dry-runThis command contacts the Let's Encrypt staging environment, performs a real validation for each certificate, and reports success or failure. It does not count against production rate limits, though staging has its own limits. A successful run ends with Congratulations, all simulated renewals succeeded.
The dry run proves that:
- Port 80 (or your DNS API) is reachable by the validation server.
- The renewal configuration under
/etc/letsencrypt/renewal/is valid. - Certbot has permission to write its files.
It also runs your deploy hook. Check the hook directory to see what will run:
sudo ls -l /etc/letsencrypt/renewal-hooks/deploy/Every script there must be executable. Certbot silently skips files without the execute bit.
Common problems
| Symptom | Likely cause | Fix |
|---|---|---|
| Server shows an old expiry date after renewal | nginx was never reloaded | Add or repair the deploy hook, then run `sudo systemctl reload nginx` |
| `unable to verify the first certificate` | nginx uses `cert.pem` instead of `fullchain.pem` | Point `ssl_certificate` at `fullchain.pem` |
| Dry run fails with a timeout or 404 | Port 80 blocked, wrong DNS, or the redirect interferes with the challenge path | Check the firewall, the A and AAAA records, and the `/.well-known/acme-challenge/` handling |
| Wrong certificate for a hostname | Missing `-servername`, or no matching `server_name` block | Test with SNI and check the nginx server blocks |
| Browser warns about a test certificate | Certificate was issued from staging | Re-issue without `--staging`, using `--force-renewal` if needed |
| No timer listed | Certbot installed without packaging | Create a systemd timer or cron job |
An AAAA record that points to a server that does not serve the site is a frequent hidden cause. Let's Encrypt prefers IPv6 when a record exists, so validation can fail even though IPv4 works. Test both with curl -4 and curl -6.
If a dry run fails, read the log:
sudo tail -n 50 /var/log/letsencrypt/letsencrypt.logThe log records the exact challenge URL and the response the validation server received, which usually identifies the cause directly.
A reusable check script
Combine the key checks into one script that you can run by hand or from monitoring.
#!/bin/sh
# Usage: ./check-cert.sh example.com
host="$1"
days=21
if echo | openssl s_client -connect "$host:443" -servername "$host" 2>/dev/null \
| openssl x509 -noout -checkend $((days * 86400)); then
echo "OK: certificate for $host is valid for more than $days days"
else
echo "WARNING: certificate for $host expires within $days days or is unreadable"
exit 1
fiThe -checkend option exits with status 0 if the certificate is still valid after the given number of seconds. Let's Encrypt renews at 30 days remaining, so an alert at 21 days means at least several renewal attempts have already failed.
Exercise
You renewed a certificate and sudo certbot certificates shows 89 days remaining. Browsers still report that the certificate expires in 3 days. Which command shows what the server actually serves, and what is the most likely cause and fix?
Show answer
Run echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates. The most likely cause is that nginx still holds the old certificate in memory because it was not reloaded after renewal. Run sudo nginx -t && sudo systemctl reload nginx, then add an executable script at /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh that runs systemctl reload nginx so future renewals reload it automatically.
Exercise
A certbot renew --dry-run fails with a timeout for www.example.com, but example.com succeeds. The site works in a browser over IPv4. Name two things to check.
Show answer
Check whether www.example.com has an AAAA (IPv6) record that points to a host not serving the site, since Let's Encrypt tries IPv6 first when it exists. Also check that the firewall and the nginx server block for www.example.com allow port 80 and serve /.well-known/acme-challenge/ without an unsuitable redirect. Test with curl -6 -I http://www.example.com/ and read /var/log/letsencrypt/letsencrypt.log.