Sub topic 14
Verifying the Certificate and Renewal
This chapter assumes you can use a Linux shell with sudo, nginx is serving your site, and Certbot has already created a Let's Encrypt certificate. You will verify both the certificate that nginx serves and the renewal process that keeps it current.
Check the certificate files
Certbot stores managed certificates below /etc/letsencrypt. The live directory contains symbolic links to the current certificate files.
sudo ls -l /etc/letsencrypt/live/example.com/
sudo certbot certificatesThe certbot certificates command reports each certificate's names, certificate file, private key file, and expiry date. Confirm that all required names, such as example.com and www.example.com, appear in the certificate.
The important files are:
| File | Purpose |
|---|---|
| `fullchain.pem` | Your server certificate followed by the intermediate certificates |
| `privkey.pem` | The private key used to prove the server's identity |
Nginx should serve fullchain.pem, not only the leaf certificate. Clients may otherwise be unable to build a complete chain of trust.
Verify what nginx serves
The files on disk do not prove that nginx is using the current certificate. Nginx may still have an old configuration loaded, or another virtual host may answer the request.
Use OpenSSL with Server Name Indication (SNI). SNI tells a server which hostname you want when several HTTPS sites share one IP address.
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
| openssl x509 -noout -subject -issuer -datesCheck the output:
subjectidentifies the certificate's subject.issueridentifies the certificate authority.notBeforeandnotAftershow the validity period.
The hostname must also appear in the certificate's Subject Alternative Name extension. To inspect it, omit the final filtering options:
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
| openssl x509 -noout -text | grep -A1 "Subject Alternative Name"A certificate can be valid and unexpired but still fail hostname verification if the requested name is absent.
Test automated renewal
Let's Encrypt certificates have a short lifetime, so renewal must be unattended. Certbot usually installs a systemd timer or another scheduled job.
systemctl list-timers | grep -i certbot
sudo certbot renew --dry-runThe dry run uses the staging service and does not replace the production certificate. It tests whether Certbot can find the certificate configuration, complete validation, and perform the renewal steps.
After a successful renewal, nginx must reload its configuration so it reads the new files:
flowchart TD
A[Certbot timer] --> B[Renewal check]
B -->|Certificate near expiry| C[ACME validation]
C --> D[Write renewed files]
D --> E[Reload nginx]
E --> F[Serve new certificate]
B -->|Not near expiry| G[Exit without changes]Diagnose common failures
| Symptom | Likely cause | Check |
|---|---|---|
| HTTP-01 validation fails | Port 80 or DNS is wrong | Check the A/AAAA records and firewall |
| Renewal succeeds but clients see the old certificate | Nginx was not reloaded | Check the deploy hook and reload logs |
| Dry run fails | Challenge or DNS configuration changed | Run Certbot with more detailed output |
| Hostname mismatch | The certificate lacks that name | Run `certbot certificates` and inspect SANs |
# Example deploy hook action
systemctl reload nginxA reload applies the new certificate without stopping existing connections. Test nginx before any manual reload:
sudo nginx -t && sudo systemctl reload nginxExercise
Why can a certificate be renewed successfully while clients still receive the old certificate?
Show answer
Certbot may have written the renewed files, but nginx still has the old certificate loaded in memory. Reload nginx after a successful renewal.