How-to guide · Automate renewal
How to automate HTTPS with NGINX's native ACME module
In one sentence
Configure NGINX to obtain and renew its own certificates, rehearse with staging, preserve ACME state and verify the deployed HTTPS certificate.
- Task
- Automate renewal
- Platforms
- Linux
- nginx
- Level
- Practitioner · 5 steps
On this page
- Before you start
- Steps
- 1. Install a module that matches your NGINX build
- 2. Prepare private persistent state
- 3. Add a staging issuer and dedicated test host
- 4. Validate configuration, reload and inspect issuance
- 5. Configure a separate production issuer
- Check it worked
- If something goes wrong
- Why this works
- Go deeper
Before you start
- A compatible NGINX installation and its official
ngx_http_acme_modulepackage. - A dedicated test hostname you control, with public A/AAAA records pointing at this server.
- Inbound ports 80 and 443, working outbound HTTPS and a DNS resolver reachable by NGINX.
- Permission to configure NGINX and persist its account keys, certificates and renewal state.
NGINX’s native ACME module obtains certificates and makes them available directly to its TLS listener. That is a different deployment path from Certbot managing certificate files. Choose one owner for a listener’s certificate lifecycle and retain a tested rollback configuration when migrating an existing site.
The released module documents HTTP-01 and TLS-ALPN-01 challenges. Its acme_certificate directive does not accept wildcard identifiers. Use the DNS-01 guide with a suitable client for wildcard issuance.
Steps
1. Install a module that matches your NGINX build
Inspect the current server before changing packages:
nginx -v
nginx -V
The official module reference links supported download and installation instructions. On Debian or Ubuntu after configuring a compatible official NGINX package repository, the open-source package is:
sudo apt install nginx-module-acme
dpkg -L nginx-module-acme
Do not assume an Ubuntu distribution NGINX binary can load a module built for a different official NGINX release. Check the package dependencies and NGINX package instructions. NGINX Plus has a separate package named nginx-plus-module-acme.
Find the installed .so and load it at the main configuration level, outside http. For the common package path:
load_module /usr/lib/nginx/modules/ngx_http_acme_module.so;
Use the path actually reported by your package and do not load it twice if the package already adds an include. nginx -t should recognise the module’s directives; an ABI or missing-symbol error is a package compatibility issue, not an ACME challenge failure.
2. Prepare private persistent state
Inspect the user directive in your NGINX configuration. The following uses the official package’s typical nginx worker account; substitute your real worker user and group:
sudo install -d -m 700 -o nginx -g nginx /var/cache/nginx/acme-lab-staging
sudo install -d -m 700 -o nginx -g nginx /var/cache/nginx/acme-lab-production
The module reference says the state directory contains account keys, issued certificates and private keys. Keep it outside the document root and preserve it across service restarts and container replacements. Losing state can trigger unnecessary registrations and issuance, increasing the risk of hitting CA limits.
3. Add a staging issuer and dedicated test host
The following belongs inside the existing http block. Replace acme-lab.example.com with your own test hostname. Replace 127.0.0.53 with a resolver reachable from this NGINX process if your host does not use systemd-resolved at that address:
resolver 127.0.0.53 valid=300s;
acme_issuer le_staging {
uri https://acme-staging-v02.api.letsencrypt.org/directory;
state_path /var/cache/nginx/acme-lab-staging;
ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
accept_terms_of_service;
}
acme_shared_zone zone=ngx_acme_shared:1M;
server {
listen 80;
server_name acme-lab.example.com;
location / { return 404; }
}
server {
listen 443 ssl;
server_name acme-lab.example.com;
acme_certificate le_staging;
ssl_certificate $acme_certificate;
ssl_certificate_key $acme_certificate_key;
ssl_certificate_cache max=2;
location / { return 200 "Native ACME is configured.\n"; }
}
The CA bundle path shown is the usual Debian/Ubuntu path; use your system’s maintained bundle. Certificate verification of the ACME server remains enabled. Review the CA’s terms before using accept_terms_of_service.
The module handles HTTP-01 challenge requests itself. The ordinary location returning 404 is intentional in the official configuration pattern; no Certbot webroot or separate challenge server is required. Ensure any front-end proxy passes the validation request to this NGINX instance.
4. Validate configuration, reload and inspect issuance
sudo nginx -t
sudo systemctl reload nginx
sudo tail -n 100 /var/log/nginx/error.log
Use your configured log path if it differs. Issuance is asynchronous: a successful configuration check does not mean a certificate has already been obtained. Follow account, challenge and issuance messages before expecting HTTPS to work.
Inspect the certificate once the listener can serve it:
openssl s_client -connect acme-lab.example.com:443 \
-servername acme-lab.example.com -showcerts </dev/null
A staging issuer is intentionally untrusted by ordinary clients. That is expected at this step; inspect its issuer and SANs without installing staging roots into your everyday browser. Successful staging issuance proves the challenge path and client integration, not public trust.
5. Configure a separate production issuer
Keep staging and production state separate. Add this issuer inside http:
acme_issuer le_production {
uri https://acme-v02.api.letsencrypt.org/directory;
state_path /var/cache/nginx/acme-lab-production;
ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
accept_terms_of_service;
}
Change the test server’s selection to:
acme_certificate le_production;
Run nginx -t, reload and follow issuance again. For a real application, replace the demonstration response with its existing routing only after confirming the production certificate. A hostname with multiple backends needs a validation design that consistently reaches the instance answering its challenge; installing the same configuration everywhere is not sufficient by itself.
Check it worked
curl --fail https://acme-lab.example.com/
openssl s_client -connect acme-lab.example.com:443 \
-servername acme-lab.example.com \
-verify_hostname acme-lab.example.com -verify_return_error </dev/null
Both should validate against your normal trusted roots, without an insecure option. Check the served names, issuer and dates. After a normal restart, verify that state persists and the same certificate remains available. Add independent expiry monitoring and check the served certificate after a subsequent renewal. Native issuance removes a separate reload hook, but renewal and monitoring still need operational ownership.
If something goes wrong
- Unknown
acme_issuerdirective: the module was not loaded, or you tested a different NGINX binary/configuration. - Cannot resolve the ACME server: check the configured resolver from the NGINX environment, especially inside containers.
- Permission denied in state storage: fix ownership for the actual worker account; do not make the directory world-readable.
- Challenge fails: verify public DNS, both address families, the ingress path and port 80. The challenge diagnostics explain CA validation failures even though this client is NGINX.
- Browser rejects the issuer: confirm the server selects
le_production, not the staging issuer. - Renewal creates repeated new accounts: check whether a deployment removed or replaced the persistent state directory.
Why this works
The module acts as the ACME client inside NGINX. It proves control of the hostname, stores issuance state and supplies the resulting certificate to the TLS listener. The certificate and private-key variables connect issuance directly to serving. The underlying domain validation and certificate lifecycle checks remain the same.
Go deeper
- NGINX released module reference: supported directives and challenge types.
- Official nginx-acme source and build instructions: compatibility and persistent-state details; development documentation may describe unreleased changes.
- NGINX Linux packages and Let’s Encrypt staging.
Early edition. Written with AI assistance and checked against primary sources; an independent expert review is planned. Found a mistake? Tell us.