Automating TLS renewal on a single NGINX or Apache server takes three things working together: an ACME client that renews early, a challenge method that keeps working after config changes, and a reload step that puts the new certificate into service without dropping traffic. This guide walks through that server-level setup with certbot and acme.sh, then shows how to prove it works before the next expiry date, not after it.
The pressure is new. In April 2025 the CA/Browser Forum adopted Ballot SC-081v3, which reduces the maximum validity of publicly trusted TLS certificates in steps starting in March 2026 and ending in March 2029, when the maximum reaches 47 days. The first step took the limit to 200 days, so every certificate issued since March 2026 now needs renewing at least twice a year, and the cadence only gets faster. A calendar reminder and a manual copy into /etc/nginx/ssl no longer scale. If you want the protocol background, ARI and architecture choices, read the ACME and Automated Certificate Management Guide; this page stays on the web server.
Key takeaways
- Treat the certificate private key and the ACME account key as non-human credentials: they authenticate your server and your renewal process, so protect, inventory and rotate them like any other secret.
- Renew on a fraction of lifetime, not a fixed day count. Certbot 4.0.0 and later renew when less than a third of the lifetime remains, which matches the Let's Encrypt recommendation and adapts as lifetimes shrink.
- Pick the challenge method that survives your config: the certbot
--nginxor--apacheinstallers for simple hosts, webroot for hosts with hand-managed configs, DNS for wildcards and servers that are not reachable on port 80. - Renewal is not finished until the web server reloads. Use a certbot deploy hook or the acme.sh
--reloadcmd, and run a config test before the reload. - Prove it with
certbot renew --dry-run, then monitor the certificate actually being served, because a renewed file on disk that NGINX never loaded still expires. - Never hardcode the intermediate certificate. Serve the full chain the CA returns, because intermediates change.
Why server-level automation matters now
Most certificate outages are not cryptographic failures. They are process failures: the renewal job stopped after an operating system upgrade, the person who knew the steps left, or the certificate renewed but the server kept serving the old one from memory. Shorter lifetimes multiply the number of times each of those failures gets a chance to happen. At 200 days a manual process fails roughly twice a year per host; at 47 days it fails nearly every month.
The ballot also shortens how long a CA may reuse domain validation evidence, eventually down to 10 days for the names in the certificate. In practice that means each renewal will usually need a fresh challenge, so a challenge path that only worked once, during the original setup, will break later. Automation has to cover validation as well as issuance and deployment.
There is an identity angle that teams often miss. The ACME account key is the credential that lets a process request certificates for your domains. The certificate private key is the credential your server uses to prove it is the real site. Both are machine credentials with owners, lifetimes and blast radius. Our Short-Lived vs Long-Lived Certificates guide covers the trade-off in depth.
Before you start
- Inventory the host. List every server name and alias each virtual host answers for. A certificate that misses a
wwwalias renews perfectly and still breaks visitors. - Check reachability. HTTP-01 validation needs the CA to reach the host on port 80 for each name. If the host sits behind a load balancer, a CDN or a firewall that blocks port 80, plan for DNS-01 instead.
- Check CAA records. If the domain publishes CAA records, they must permit the CA your client uses. This matters for acme.sh in particular, because its default CA is ZeroSSL rather than Let's Encrypt.
- Back up the web server config. The certbot NGINX documentation recommends a backup before letting the installer edit files, and offers
certbot --nginx rollbackto revert its changes. - Decide who owns it. Name a team that receives renewal failure alerts. A job that fails silently is worse than no job, because it creates false confidence.
Option 1: certbot with the NGINX or Apache installer
The quickest route on a standard Debian, Ubuntu, Fedora or RHEL family host is certbot with its built-in installer plugins. According to the Certbot user guide, the --apache plugin automates obtaining and installing certificates on Apache, and the --nginx plugin does the same for NGINX.
- Install certbot and the matching plugin from your distribution or the method the certbot project recommends for your platform.
- Run
certbot --nginx -d example.com -d www.example.com(or--apache). Certbot answers the HTTP-01 challenge through the running server, edits the matching virtual host to point at the new files, and stores the settings it used. - Read the diff. Confirm which server block or virtual host certbot edited and that it did not touch a block you manage elsewhere with configuration management.
- Check the schedule. Most packaged installs configure automatic renewal already. The guide says to look for
certbot renewin/etc/crontab,/etc/cron.*/*or the output ofsystemctl list-timers.
Installer mode is convenient, but it edits files. If NGINX or Apache config is generated by Ansible, Puppet, Chef or a template, the next configuration run may overwrite certbot's changes, and renewal will appear to work while the server points at the wrong path. In that case use webroot mode instead.
Option 2: certbot with webroot and your own config
Webroot mode separates validation from installation. Certbot writes challenge files to ${webroot-path}/.well-known/acme-challenge and the running server serves them. You keep full control of the TLS directives.
- Make sure every name serves
/.well-known/acme-challenge/over plain HTTP from a known directory, even if all other port 80 traffic redirects to HTTPS. In NGINX that is alocation ^~ /.well-known/acme-challenge/block with arootabove the redirect. In Apache it is anAliasor a rewrite exception for that path. - Issue with
certbot certonly --webroot -w /var/www/acme -d example.com -d www.example.com. - Point the server at the stable live paths. Certbot keeps the current files under
/etc/letsencrypt/live/example.com/and updates those links on each renewal.- NGINX:
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;andssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; - Apache 2.4.8 and later:
SSLCertificateFilepointing atfullchain.pemandSSLCertificateKeyFilepointing atprivkey.pem.
- NGINX:
- Do not copy the files elsewhere. Copies go stale. Reference the live path directly so a reload is all that is needed.
The certbot guide notes that cert.pem and chain.pem are less common and that if you use one you must provide both. Using fullchain.pem avoids the classic broken-chain error where browsers accept the site but API clients and older devices reject it.
If you later move the webroot, use certbot reconfigure (available from certbot 2.3.0). It runs a test renewal against the staging server and only saves the new options if the test succeeds, for example certbot reconfigure --cert-name example.com --webroot-path /path/to/new/location. The guide discourages hand-editing /etc/letsencrypt/renewal/CERTNAME.conf.
Option 3: acme.sh for hosts where you want a shell-only client
acme.sh is a shell script ACME client that suits minimal images, appliances and hosts where you prefer not to install Python packages. Per the acme.sh project README, the installer creates a daily cron job that checks and renews certificates.
- Choose the CA explicitly. The default CA is ZeroSSL. Use
--server letsencrypt(or your chosen CA) so that behaviour, CAA records and rate limits are what you expect. - Issue. Use
-w /var/www/acmefor webroot,--nginxor--apacheto answer challenges through the running server without changing its config, or--dnswith a provider plugin such asdns_cffor wildcard certificates. - Key type. The README uses
--keylength ec-256, which is the default. - Install, then reload. acme.sh keeps its working copies in its own directory. Use
--install-certwith--key-file,--fullchain-fileand--reloadcmdto copy files to the paths the server reads and restart it gracefully. The README states that thereloadcmdis very important. Without it, the files change on disk and the server keeps serving the old certificate. - Timing. The README describes renewal every 30 days, earlier if the CA's ARI suggested window has started. Check the current documentation if your certificates are shorter lived.
A typical install line looks like acme.sh --install-cert -d example.com --key-file /etc/nginx/tls/example.com.key --fullchain-file /etc/nginx/tls/example.com.pem --reloadcmd "nginx -t && systemctl reload nginx". acme.sh remembers these settings and reapplies them on every renewal.
DNS-01 for wildcards and private servers
DNS validation is the only ACME method for wildcard names and the practical choice for servers that cannot be reached on port 80. It moves the risk: the client now needs a credential that can write DNS records.
- Scope the DNS API token to the single zone, and ideally to TXT records under
_acme-challenge, if the provider supports it. A token that can edit any record in any zone is a domain takeover credential. - Store the token in a file readable only by the renewal user, or fetch it from a secrets manager at run time. acme.sh saves provider credentials in its account configuration, so restrict that directory.
- Consider CNAME delegation: point
_acme-challenge.example.comat a record in a separate, low-value zone, and give the client rights only on that zone. - Inventory these tokens with your other non-human identities. They are long lived by default and rarely reviewed.
Safe reloads: deploy hooks and graceful restarts
NGINX and Apache read certificate files at start-up and on reload. A renewed file is invisible until one of those happens. The aim is a graceful reload, which keeps existing connections open while workers pick up the new files, and never a hard restart that can drop traffic or fail to come back.
Certbot gives you three hook types, documented in the user guide:
--pre-hookand--post-hookrun before and after each renewal attempt, only when a certificate is due.--deploy-hookruns only after a successful issuance or renewal. This is the right place for a reload. From certbot 2.7.0, hooks can readRENEWED_DOMAINSandFAILED_DOMAINS.- Executables in
/etc/letsencrypt/renewal-hooks/pre,deployandpostrun in alphabetical order. Since certbot 3.2.0 they run for any subcommand, not onlyrenew.
A minimal deploy hook for NGINX, saved as /etc/letsencrypt/renewal-hooks/deploy/10-reload-nginx and made executable:
#!/bin/sh
nginx -t && systemctl reload nginx
For Apache, use apachectl configtest && systemctl reload apache2 (or httpd on RHEL family systems). The config test matters: if someone left a broken edit in place, a reload without a test can take the site down at 3am on renewal night.
Two points from the certbot guide are worth building around. First, a failing hook prints to stderr but renewal is still attempted, so watch hook output, not only the renewal exit code. Second, certbot renew returns 1 only when a renewal attempt fails and 0 when nothing was due, which makes the exit status usable in monitoring.
If the same certificate feeds other services, such as a mail server, a load balancer or a container, add a hook for each and keep them idempotent. Avoid using standalone mode on a live web server: it binds port 80 itself, so the web server would need stopping for every renewal.
Keys, accounts and file permissions
- Key type. Certbot defaults to ECDSA keys from version 2.0.0, with
--key-typeacceptingrsaorecdsa. Let's Encrypt accepts RSA 2048, 3072 and 4096 and ECDSA P-256 and P-384. Check old clients before switching a site that serves legacy devices. - Key reuse. Certbot's
--reuse-keydefaults to False, so a new private key is generated on each renewal. Keep that default unless you pin keys somewhere, because frequent key rotation limits the value of a stolen key. - Permissions. Certbot creates its directories with mode 0700. Keep
privkey.pemreadable only by root and the web server's master process. Do not loosen/etc/letsencryptto let an application user read keys. - Account key. The Let's Encrypt integration guide recommends a single account with a well-guarded account key, and notes that you cannot reuse an account key as a certificate key. Back up the account directory with the same care as the certificate keys, and exclude it from images that get shared.
- Leaked keys. If a private key may have leaked, revoke and replace rather than waiting for renewal. See the Leaked TLS Private Key Response.
Verify it worked
- Run
certbot renew --dry-run. It uses the Let's Encrypt staging server unless--serveris set. Deploy hooks are skipped during a dry run unless you add--run-deploy-hooks, so add it once to test the reload path. - For acme.sh, run a forced renewal against staging for one name, then confirm the reload command ran.
- Check what the server is actually serving, from outside the host:
openssl s_client -connect example.com:443 -servername example.com, then read thenotAfterdate and confirm the full chain is presented. - Repeat for every name and every virtual host. SNI means each name can serve a different certificate.
- Record the result in your certificate inventory, including the client, challenge method, hook and owner.
Monitoring and failure handling
The Let's Encrypt integration guide makes several recommendations that apply directly to a server fleet:
- Use ARI where the client supports it, with renewal at a third of lifetime remaining as a backstop.
- Run scheduled jobs at a randomised time of day rather than on the hour, to avoid load spikes at the CA. Packaged certbot timers already add a random delay; check yours.
- Do not treat a renewal failure as fatal. Retry with exponential backoff capped at once a day, and report every error to the responsible administrator.
- Do not hardcode the intermediate. Serve the chain the CA returns.
On top of that, monitor from the outside. Alert when a served certificate has less than a third of its lifetime left, because by then the client should already have renewed it. External checks catch the cases that local logs miss: a reload that never happened, a load balancer still holding an old copy, or a name that was dropped from the renewal configuration. Certificate Transparency monitoring also shows you every certificate issued for your domains, including ones you did not request; see our Certificate Transparency Monitoring Guide for Web Teams.
Rollback and common errors
- Installer changed the wrong block. Run
certbot --nginx rollback, restore from backup, then move to webroot mode. - HTTP-01 fails after a redirect change. A new site-wide HTTPS redirect or authentication rule now catches
/.well-known/acme-challenge/. Add an exception ahead of the redirect. - Renewed but still expiring. The server never reloaded. Add or fix the deploy hook or
--reloadcmd. - Chain errors in API clients. The server points at
cert.peminstead offullchain.pem. - Rate limits. Repeated live attempts while debugging. Use
--dry-runor the staging server until the path works. Do not schedule--force-renewal; the certbot guide warns against running it daily. - CAA rejection with acme.sh. The client is using its default CA, which the CAA record does not permit. Set
--serverexplicitly.
For a structured response when a certificate does expire in production, use the Expired Certificate Outage Troubleshooting Guide.
Common failure patterns
- Renewal automated, reload forgotten, so the certificate renews on disk and expires in memory.
- Configuration management overwriting certbot installer edits, so the server points at a stale path.
- Fixed 30-day renewal thresholds left in place on old clients as lifetimes shrink.
- Broad DNS API tokens stored in plain text on every web server.
- Monitoring only the job exit code rather than the certificate actually served.
- Copying keys between hosts by hand, which leaves unmanaged copies with no owner.
- Web server images built with an ACME account directory baked in, sharing one account key across every clone.
Practitioner checklist
- Every name and alias on each virtual host is listed in the renewal configuration.
- Challenge method chosen per host: installer, webroot or DNS-01, and documented.
- Server config references the client's live or install paths, never ad hoc copies.
- Deploy hook or
--reloadcmdruns a config test, then a graceful reload. - Client renews on a fraction of lifetime or ARI, not a fixed 30 days.
- CA set explicitly and permitted by CAA records.
- DNS API tokens scoped to the minimum zone and records, and stored with restricted permissions.
- Private keys and the ACME account key readable only by root and the server process, and backed up securely.
certbot renew --dry-run --run-deploy-hookspasses after every OS or config change.- External monitoring alerts when a served certificate has less than a third of its lifetime left.
- A named owner receives renewal and hook failure alerts.
Standards and references
- IETF: RFC 8555, Automatic Certificate Management Environment (ACME)
- IETF: RFC 9773 ACME Renewal Information (ARI) Extension
- CA/Browser Forum: Ballot SC-081v3, schedule of reducing validity and data reuse periods
- Certbot documentation: User Guide
- acme.sh project README
- Let's Encrypt: Integration Guide
- Certificate Expiry Outages and 47-Day TLS Certificates Guide
Related NHI Mgmt Group resources: ACME and Automated Certificate Management Guide · Certificate Renewal Runbook Template · NGINX Security Hardening Guide · Apache HTTP Server Hardening Guide