Sub topic 7
Testing safely with staging and respecting rate limits
This chapter assumes you can use a Linux shell with sudo, you have nginx running on a server, and you control a registered domain whose DNS points at that server. It also assumes you have installed Certbot (covered in the previous chapter) and know that Let's Encrypt validates domain control through the ACME protocol.
Why a staging environment exists
Let's Encrypt is a free certificate authority (CA) that serves a very large number of sites. To keep the service available for everyone, it limits how many certificates and requests a single account, domain or IP address can make. These are called rate limits.
Mistakes are common during the first setup. A firewall blocks port 80, a DNS record points at the wrong host, or a typo appears in a domain name. Each failed attempt counts against some of those limits. If you debug against the production service, you can lock yourself out for hours or days.
The staging environment solves this. It runs the same ACME software as production, but it has much higher limits. Its certificates come from an untrusted test CA, so browsers reject them. That is intentional: you can rehearse the whole process without consuming production quota, and nobody can mistake a test certificate for a real one.
| Property | Production | Staging |
|---|---|---|
| Certificates trusted by browsers | Yes | No |
| Rate limits | Strict | Much higher |
| Use for | Real sites | Rehearsals and debugging |
| Certbot flag | (default) | `--staging` |
| Issuer name contains | `Let's Encrypt` | `(STAGING)` |
Running a staging request
Use certonly so Certbot obtains the certificate but does not edit your nginx configuration. The --nginx plugin answers the HTTP-01 challenge for you.
sudo certbot certonly --nginx --staging \
-d example.com -d www.example.comReplace example.com with your own domain. Certbot asks for an email address and for agreement to the terms of service on the first run. It then contacts the staging server, completes the challenge for each name, and stores the result under /etc/letsencrypt/.
If this succeeds, you have shown that several things work together:
- Your DNS records resolve to this server for every name you listed.
- Port 80 is reachable from the internet.
- nginx can serve the challenge file.
- Certbot can write to
/etc/letsencrypt/.
If it fails, read the error message. Certbot reports which name failed and usually why. Fix the cause and run the same command again. You can repeat this as often as you need without worrying about production limits.
Telling staging and production apart
Staging certificates live in the same directory layout as production ones. List what Certbot knows about:
sudo ls -l /etc/letsencrypt/live/example.com/
sudo certbot certificatesThe output of certbot certificates shows each certificate's domains and expiry date. For a staging certificate, it also marks the certificate as a test certificate (look for INVALID: TEST_CERT next to the expiry). You can also inspect the issuer directly.
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
| openssl x509 -noout -subject -issuer -datesThis only works once nginx is serving the certificate on port 443. A staging issuer line includes the text (STAGING). A production issuer line names a Let's Encrypt intermediate CA such as R10 or E5, and the exact names change over time.
Moving from staging to production
A staging certificate is stored under a lineage name, which by default is the first domain you requested. If you now request a production certificate for the same names, Certbot may find the existing lineage and ask whether to keep it or replace it. Replacing a lineage is what you want here. The following command requests the real certificate:
sudo certbot certonly --nginx \
-d example.com -d www.example.comIf Certbot offers a choice, pick the option to renew and replace the existing certificate. Afterwards, run sudo certbot certificates and confirm the test-certificate marker is gone.
Two details can trip you up:
- Certbot saves the server it used in the renewal configuration file under
/etc/letsencrypt/renewal/. If the lineage still points at staging, automatic renewals keep producing test certificates. Check that file after switching. - If nginx already references the lineage's
fullchain.pemandprivkey.pem, it keeps serving the old certificate until you reload it. Runsudo nginx -t && sudo systemctl reload nginxafter the switch.
sudo nginx -t && sudo systemctl reload nginxThe nginx -t part checks the configuration first, so a typo does not take the site down. The reload happens only if the check passes.
The rate limits that matter
Let's Encrypt publishes its limits and adjusts them from time to time, so treat the numbers below as examples and check the current documentation at letsencrypt.org/docs/rate-limits before you plan around them. What stays stable is the kind of limit.
| Limit type | What it counts | Why it matters to you |
|---|---|---|
| Certificates per registered domain | New certificates issued for a domain and its subdomains within a time window | Spinning up many subdomains each with its own certificate can hit this |
| Duplicate certificates | Identical sets of names requested again within a window | Re-requesting the same certificate repeatedly during debugging |
| Failed validations | Failed challenges per account, per hostname, within a window | A broken setup retried in a loop |
| New orders and new accounts | Requests per account or per IP address | Automation that creates a fresh account on each run |
The duplicate certificate limit is the one beginners meet most often. If you request a production certificate for the same names several times in a row, for example because you deleted /etc/letsencrypt and started over, the service refuses further identical requests until the window passes. Staging avoids this.
A related rule: renewals are treated more gently than new issuance. Renewing a certificate for exactly the same set of names is exempt from some of the limits, which is one more reason to keep a stable set of names on a certificate instead of changing the list often.
What happens when you hit a limit
Certbot prints the error from the server. It names the limit and often gives a time after which you may retry. The error is not a Certbot fault and no local setting clears it. Your options are:
- Wait until the window ends. The message usually states the retry time.
- Change the request so it is not a duplicate, for instance by adding or removing a name, if that fits your real need.
- Move your debugging to staging and return to production only for the final request.
Do not work around a limit by creating many accounts or by rotating IP addresses. That is a misuse of the service, and the new-account limits exist to stop it.
A safe workflow
The order below keeps production usage to a minimum and puts every failure in the cheap environment.
- Check DNS and firewall: every name resolves to the server, and ports 80 and 443 are open.
- Run
certbot certonly --nginx --stagingfor the exact names you want. - Fix any failure and repeat step 2 until it succeeds.
- Run the same command without
--stagingonce. - Confirm with
certbot certificatesandopenssl s_clientthat the certificate is real. - Test renewal with a dry run.
systemctl list-timers | grep -i certbot
sudo certbot renew --dry-runThe --dry-run option is also safe for production certificates. It performs a full renewal simulation against the staging environment and does not replace your live certificate. It checks that the renewal configuration, the challenge method and the plugin all still work, so run it after every change to your setup.
Common mistakes
- Browser warnings after "success". You left the staging certificate in place. The issuer shows
(STAGING). Request the production certificate and reload nginx. - Renewals produce test certificates. The renewal file for the lineage still names the staging server. Fix it by re-issuing the certificate without
--staging. - Deleting
/etc/letsencryptto "start fresh". You lose the account key and certificates, and you may trigger the duplicate certificate limit when you request them again. Back up the directory instead. - Retrying a failing production request in a loop. Each failure counts toward the failed validation limit. Stop after one failure and move to staging.
- Testing a name that is not ready. A name with no DNS record, or with a record pointing elsewhere, fails validation every time. Check with
dig +short example.comfirst.
Exercises
Exercise
You requested a production certificate three times today for the same two names while debugging a firewall problem, and the fourth request now fails with an error about too many certificates. Which limit did you most likely hit, and what should you have done instead?
Show answer
You most likely hit the duplicate certificate limit, which restricts repeated requests for an identical set of names within a time window. You should have debugged the firewall problem using certbot certonly --nginx --staging for the same names, which has much higher limits, and run the production request only once after staging succeeded.
Exercise
After switching from staging to production, certbot certificates shows a valid production certificate, but your browser still shows a warning and openssl s_client reports an issuer containing "(STAGING)". What is the likely cause and the fix?
Show answer
nginx is still serving the old staging certificate because it has not reloaded its configuration. Run sudo nginx -t && sudo systemctl reload nginx, then check the issuer again with openssl s_client. Also confirm that the nginx configuration points at the correct lineage directory under /etc/letsencrypt/live/.