Sub topic 2
Testing safely with staging and respecting rate limits
This chapter assumes you can use a Linux shell with sudo, that nginx is already running on a server, and that a DNS A record points your domain to that server. Ports 80 and 443 must be reachable from the internet. Let's Encrypt is a free certificate authority (CA) that issues certificates through the ACME protocol. Certbot is the client program that requests them.
Testing safely with staging and respecting rate limits
Let's Encrypt runs a staging environment that follows the production steps but issues certificates from an untrusted test CA. Use staging to confirm that domain validation works before you request a real certificate. Production enforces rate limits, which cap the number of certificates and failed validations you can request in a set period. Repeated failures can block you for hours or days. Check the current limits on the Let's Encrypt website, because they change.
Obtaining your first certificate
After a successful staging run, request the production certificate for both names:
sudo certbot certonly --nginx \
-d example.com -d www.example.comThe certonly option fetches the certificate without changing nginx. You configure nginx yourself in the next section.
Understanding the certificate files Certbot creates
Certbot stores certificates under /etc/letsencrypt/live/example.com/. Those entries are symlinks to versioned files in archive/, so renewals can swap the links without changing your nginx paths.
| File | Contents |
|---|---|
| cert.pem | Your server certificate only |
| chain.pem | Intermediate CA certificate |
| fullchain.pem | cert.pem plus chain.pem, which nginx needs |
| privkey.pem | Private key, which must stay secret |
Serving the certificate from nginx
Point nginx at fullchain.pem, not cert.pem. Browsers need the intermediate certificate to build the chain of trust.
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name example.com www.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
root /var/www/html;
}Redirecting HTTP to HTTPS and enabling HSTS
Add a port 80 server block that sends all plain HTTP requests to HTTPS. Then add an HSTS header to the HTTPS block so browsers use HTTPS for the domain automatically.
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}Add this line inside the 443 block:
add_header Strict-Transport-Security "max-age=31536000" always;Test the configuration before reloading:
sudo nginx -t && sudo systemctl reload nginx> Callout: HSTS tells browsers to refuse plain HTTP for max-age seconds. The value above is one year. Enable it only after HTTPS works for every subdomain you serve.
Exercise
You get a validation error from a production request and you are still debugging DNS. Why should you switch back to --staging?
Show answer
Failed production validations count toward rate limits. Staging has much higher limits and issues only test certificates, so repeated attempts there do not block your production requests.