Sub topic 9
Understanding the Certificate Files Certbot Creates
This chapter assumes you can use a Linux shell with sudo, have nginx installed, and understand basic file paths and symbolic links. You will learn how Certbot stores certificates and which files nginx should use.
The `/etc/letsencrypt` layout
Certbot normally stores its data under /etc/letsencrypt. The most important directories are:
live/contains the certificate files that web servers should use.archive/contains the actual certificate and key versions.renewal/contains configuration for renewing each certificate.accounts/contains ACME account information used to communicate with Let's Encrypt.
For a certificate named example.com, inspect the live directory:
sudo ls -l /etc/letsencrypt/live/example.com/
sudo certbot certificatesThe live/example.com/ directory usually contains these files:
| File | Contents | Typical nginx use |
|---|---|---|
| `cert.pem` | The certificate for your domain | Usually not used directly |
| `chain.pem` | Intermediate CA certificates | Usually not used directly |
| `fullchain.pem` | Your certificate followed by the intermediate chain | `ssl_certificate` |
| `privkey.pem` | The private key for your certificate | `ssl_certificate_key` |
Why `live` contains symbolic links
The files in live/ are usually symbolic links. A symbolic link is a filesystem entry that points to another file. Certbot creates new files in archive/ when it renews a certificate, then updates the links in live/ to point to the newest versions.
For example, you might see:
cert.pem -> ../../archive/example.com/cert2.pem
fullchain.pem -> ../../archive/example.com/fullchain2.pem
privkey.pem -> ../../archive/example.com/privkey2.pemYour nginx configuration should refer to the stable paths in live/, not to numbered files in archive/. This lets Certbot change the certificate version without requiring you to edit nginx configuration.
Choosing the correct certificate file
A server sends its own certificate and the intermediate certificates needed by browsers to build a chain of trust. The fullchain.pem file contains both parts, so nginx should use it:
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
root /var/www/html;
}The private key proves that the server controls the certificate. Keep it secret. Do not email it, commit it to source control, or make it readable by ordinary users.
The chain.pem file contains only intermediate certificates. Using it as ssl_certificate can cause incomplete certificate-chain errors. The cert.pem file contains only your server certificate and may also cause clients to fail to build the chain.
> callout warning > Never replace fullchain.pem with cert.pem unless you have a specific reason and understand how your server supplies the intermediate chain.
Checking ownership and permissions
Inspect permissions without printing the private key:
sudo stat -c '%A %U:%G %n' \
/etc/letsencrypt/live/example.com/fullchain.pem \
/etc/letsencrypt/live/example.com/privkey.pemThe private key should be readable by root and by the account that starts nginx, according to your distribution's service permissions. Avoid changing permissions broadly. If nginx cannot read the key, its configuration test will report a permission error.
After a renewal, nginx may still have the old certificate loaded in memory. A successful renewal therefore normally needs a graceful nginx reload.
sudo nginx -t && sudo systemctl reload nginxExercise
Which two Certbot paths should nginx normally use for TLS, and why should you avoid paths in the archive directory?
Show answer
Use /etc/letsencrypt/live/example.com/fullchain.pem and /etc/letsencrypt/live/example.com/privkey.pem. The live paths remain stable while Certbot updates their symbolic links to newer files in the archive directory.