<!-- https://pkizerotohero.com/guides/nginx-native-acme/ | Markdown mirror of the HTML page | PKI Zero to Hero, by Duyutech BV -->

> Set up NGINX native ACME with ngx_http_acme_module: compatible packages, staging and production issuers, persistent state and certificate checks.

Source: https://pkizerotohero.com/guides/nginx-native-acme/ · Last reviewed: 2026-10-25

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](https://pkizerotohero.com/guides/#task-automate)

Platforms

- Linux
- nginx

Who it is for

- [IT ops](https://pkizerotohero.com/start/#itops)
- [Developer](https://pkizerotohero.com/start/#developer)

Level

Practitioner · 5 steps

## Before you start

- A compatible NGINX installation and its official `ngx_http_acme_module` package.
- 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](https://nginx.org/en/docs/http/ngx_http_acme_module.html) obtains certificates and makes them available directly to its TLS listener. That is a different deployment path from [Certbot managing certificate files](https://pkizerotohero.com/guides/certbot-lets-encrypt/). 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](https://pkizerotohero.com/guides/wildcard-dns-01/) with a suitable client for wildcard issuance.

## Steps

### 1. Install a module that matches your NGINX build

Inspect the current server before changing packages:

```bash
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:

```bash
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](https://nginx.org/en/linux_packages.html). 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:

```nginx
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:

```bash
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](https://nginx.org/en/docs/http/ngx_http_acme_module.html#state_path) 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:

```nginx
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

```bash
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:

```bash
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`:

```nginx
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:

```nginx
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

```bash
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](https://pkizerotohero.com/guides/check-certificate-expiry/) 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_issuer` directive:** 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](https://pkizerotohero.com/errors/certbot-some-challenges-failed/) 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](https://pkizerotohero.com/handbook/acme/) 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](https://pkizerotohero.com/handbook/domain-validation/) and [certificate lifecycle](https://pkizerotohero.com/handbook/certificate-lifecycle/) checks remain the same.

## Go deeper

- [NGINX released module reference](https://nginx.org/en/docs/http/ngx_http_acme_module.html): supported directives and challenge types.
- [Official nginx-acme source and build instructions](https://github.com/nginx/nginx-acme): compatibility and persistent-state details; development documentation may describe unreleased changes.
- [NGINX Linux packages](https://nginx.org/en/linux_packages.html) and [Let’s Encrypt staging](https://letsencrypt.org/docs/staging-environment/).

**Early edition.** Written with AI assistance and checked against primary sources; an independent expert review is planned. Found a mistake? [Tell us](https://pkizerotohero.com/contact/?topic=content-error&page=/guides/nginx-native-acme/).

Last reviewed 25 October 2026Edition 0.9

## Keep going

### Learn why it works

- [Chapter 20: ACME and the 47-day schedule](https://pkizerotohero.com/handbook/acme/)
- [Chapter 19: Inventory, expiry and renewal](https://pkizerotohero.com/handbook/certificate-lifecycle/)
- [Chapter 11: Proving you own the name: DV, OV, EV and CAA](https://pkizerotohero.com/handbook/domain-validation/)

### Error pages

- [certbot: Some challenges have failed](https://pkizerotohero.com/errors/certbot-some-challenges-failed/)
- [NET::ERR\_CERT\_AUTHORITY\_INVALID](https://pkizerotohero.com/errors/chrome-err-cert-authority-invalid/)

### Tools

- [Certificate decoder](https://pkizerotohero.com/tools/decoder/): Paste a PEM certificate and read every field in plain words.

### Topics

- [TLS and HTTPS](https://pkizerotohero.com/topics/tls/)
- [Lifecycle and automation](https://pkizerotohero.com/topics/lifecycle-and-automation/)

## More guides: Automate renewal

- [How to get and renew Let's Encrypt certificates with certbot](https://pkizerotohero.com/guides/certbot-lets-encrypt/)
- [How to automate certificates in Kubernetes with cert-manager](https://pkizerotohero.com/guides/kubernetes-cert-manager/)
- [How to automate certificates on Windows with win-acme](https://pkizerotohero.com/guides/win-acme-windows/)
- [How to get a wildcard certificate with DNS-01](https://pkizerotohero.com/guides/wildcard-dns-01/)
- [How to get a Let's Encrypt certificate for an IP address](https://pkizerotohero.com/guides/lets-encrypt-ip-address-certificate/)
