Automatic Certificate Renewal (ACME)
ProxyAuth can obtain and renew Let's Encrypt certificates entirely on its own — no external certbot/acme.sh, no cron job, no deploy hook. Set certbot_renew: true on a vhost and ProxyAuth handles the whole lifecycle: checking expiry, running the HTTP-01 challenge, writing the new certificate, and picking it up live.
If you'd rather manage certificates with an external tool instead, see TLS & Certificates § Using external Let's Encrypt / certbot.
How it works
flowchart TD
A(["Periodic scan<br/>every letsencrypt.check_interval_secs (default hourly)"]) --> B{"Certificate missing,<br/>or within renew_before_days<br/>of expiring?"}
B -->|no| A
B -->|yes| C["Create/reuse ACME account<br/>(credentials persisted to disk)"]
C --> D["Request an order from Let's Encrypt<br/>for this vhost's hostname"]
D --> E["Publish the HTTP-01 challenge response<br/>in-memory, ahead of normal routing"]
E --> F["Tell Let's Encrypt we're ready —<br/>their servers fetch the challenge URL"]
F --> G{"Challenge<br/>validated?"}
G -->|no| H(["Challenge response removed<br/>currently valid certificate keeps being used"])
G -->|yes| I["Finalize the order, download<br/>the new certificate chain"]
I --> J["Write fullchain.pem + privkey.pem<br/>atomically (temp file + rename)"]
J --> K["Challenge response removed"]
K --> L(["Existing file watcher (vhost_cert)<br/>picks up the change and hot-reloads —<br/>nothing new needed for this part"])
classDef edge fill:#eef2ff,stroke:#4f46e5,stroke-width:1px,color:#1e1b4b
classDef step fill:#f8fafc,stroke:#64748b,stroke-width:1px,color:#0f172a
classDef decision fill:#fde68a,stroke:#d97706,stroke-width:1px,color:#78350f
classDef done fill:#dcfce7,stroke:#16a34a,stroke-width:1px,color:#14532d
classDef fail fill:#fee2e2,stroke:#dc2626,stroke-width:1px,color:#7f1d1d
class A edge
class B,G decision
class C,D,E,F,I,J,K step
class L done
class H fail
A few design points worth understanding before turning this on:
- The HTTP-01 challenge response lives only in RAM, published just ahead of normal routing for the exact duration of one renewal attempt, and removed immediately after (success or failure). It's never written to
routes.yml— there's nothing to see there before, during, or after a renewal. - Nothing new handles the actual TLS hot-reload. The certificate/key files ACME writes to are the same paths already configured in
vhost_cert— the file watcher that already hot-reloads a certificate you replaced by hand (see TLS & Certificates § Per-vhost certificates) picks up ACME's writes the same way, automatically. - A failed renewal never touches the currently valid certificate. Files are only written once the new certificate is fully obtained — if anything fails along the way (network error, DNS misconfiguration, rate limit, invalid challenge), whatever certificate was already on disk is left completely alone and keeps being served.
- The scan runs once immediately at startup, then on the configured interval — a genuinely new vhost doesn't wait a full interval for its first certificate.
Manual control from the CLI
The same mechanism is also available on demand, without waiting for the periodic scan:
proxyauth certbot renew app.example.com # renew now, if due
proxyauth certbot renew app.example.com --force # renew now, unconditionally
proxyauth certbot renew all # renew every certbot_renew: true vhost that's due
proxyauth certbot check app.example.com # print certificate details (subject, issuer, expiry...)
proxyauth certbot new app.example.com # issue a first certificate for a brand-new vhost
Full flag reference and example output: CLI Reference § proxyauth certbot renew (and the check/new sections right after it).
Configuration
routes.yml
- vhost: ["app.example.com"]
vhost_cert:
cert: /etc/proxyauth/cert/app.example.com/fullchain.pem
key: /etc/proxyauth/cert/app.example.com/privkey.pem
certbot_renew: true
prefix: "/"
target: "http://127.0.0.1:8000"
| Key | Description |
|---|---|
vhost_cert |
Required. Where ACME writes the certificate — must already be set, pointing at the paths you want the issued certificate to live at. See below for why this needs to exist before the first renewal. |
certbot_renew |
Set to true to enable automatic renewal for this vhost. |
If more than one route shares the same vhost, setting certbot_renew/vhost_cert on just one of them is enough — ProxyAuth looks these up per-hostname across every route, not per individual route entry.
config.json
"letsencrypt": {
"check_interval_secs": 3600,
"renew_before_days": 30,
"directory_url": "https://acme-v02.api.letsencrypt.org/directory",
"contact_email": "you@example.com",
"account_credentials_path": "/etc/proxyauth/acme/account.json"
}
All fields optional — everything above is also the default, except directory_url, which you should point at Let's Encrypt's staging environment while testing (see below). acme is also still accepted as an alias for this key, for configs written before it was renamed to letsencrypt.
| Key | Type | Default | Description |
|---|---|---|---|
check_interval_secs |
integer | 3600 (hourly) |
How often ProxyAuth checks every certbot_renew: true vhost's certificate. This is a check interval, not a renewal interval — most checks find nothing due and do nothing. |
renew_before_days |
integer | 30 |
Renew when the certificate has this many days or fewer left. Let's Encrypt certificates are valid 90 days; 30 matches Certbot's own default and leaves comfortable margin for a failed attempt or two. |
directory_url |
string | Let's Encrypt production | The ACME directory URL. Point this at staging while testing — see below. Switching between staging and production is safe at any time: staging and production are separate ACME servers with separate account databases, and ProxyAuth tracks which one the saved account was registered against — changing directory_url automatically registers a fresh account for the new environment instead of reusing the wrong one (a certificate that stubbornly keeps coming back with (STAGING) in its issuer, even after switching directory_url to production, is the symptom of an older ProxyAuth version that didn't yet track this — upgrading resolves it without needing to manually delete anything). |
contact_email |
string | (none) | Contact email for the ACME account. Optional, but recommended — it's how Let's Encrypt would reach you about an issue with your account or an expiring certificate they notice you haven't renewed. |
account_credentials_path |
string | /etc/proxyauth/acme/account.json |
Where the ACME account's key is persisted between restarts, so ProxyAuth doesn't register a brand-new account every time it starts (which is itself something Let's Encrypt rate-limits). One account per file — if this same path is ever reused across a directory_url change, ProxyAuth detects the mismatch and transparently registers a new account for the new environment rather than reusing the old one. Written with 0600 permissions — this is effectively a bearer credential for the account. |
Before you turn this on
Test against staging first. Let's Encrypt's production environment has strict rate limits — a handful of certificates per registered domain per week — and a misconfiguration you're still debugging will burn through them fast. Staging has no meaningful rate limits and exercises the exact same code path; the only difference is it issues certificates from a CA nothing trusts by default, which is fine for confirming the mechanism actually works end-to-end.
"letsencrypt": {
"directory_url": "https://acme-staging-v02.api.letsencrypt.org/directory"
}
Switch to the production URL (or just remove the override, since it's the default) only once you've confirmed a full renewal cycle succeeds against staging.
An initial certificate needs to already exist at the vhost_cert paths. The file watcher that hot-reloads a renewed certificate is set up once at startup by reading whatever's already at those paths — if nothing's there yet, that watcher never starts for this vhost, and there's nothing to hot-reload into once ACME does issue a certificate. A self-signed placeholder is enough to bootstrap this:
mkdir -p /etc/proxyauth/cert/app.example.com
openssl req -x509 -newkey rsa:2048 -sha256 -days 1 -nodes \
-keyout /etc/proxyauth/cert/app.example.com/privkey.pem \
-out /etc/proxyauth/cert/app.example.com/fullchain.pem \
-subj "/CN=app.example.com"
The first successful ACME renewal replaces this placeholder immediately, so its own (deliberately short) 1-day validity doesn't matter.
The domain needs to be publicly resolvable and reachable on port 80. Let's Encrypt's validation servers always fetch http://{vhost}/.well-known/acme-challenge/{token} over plain HTTP on port 80 specifically — this isn't configurable on their end. ProxyAuth handles answering on port 80 automatically (see § The HTTP-01 listener on port 80 below) — what it can't do anything about is a firewall, router, or cloud security group blocking that port from the public internet. Confirm port 80 is actually open there before assuming a renewal failure is ProxyAuth's fault.
The HTTP-01 listener on port 80
A TLS-only deployment (the common case: everything real served over 443, nothing else listening) has no way to answer an HTTP-01 challenge on its own — actix-web doesn't support mixing a TLS listener and a plain-HTTP listener within the same server instance. To solve this, ProxyAuth automatically spawns a second, minimal, plain-HTTP-only server bound to port 80 (on the same address(es) as host in config.json), whose only job is answering /.well-known/acme-challenge/* and redirecting everything else to HTTPS.
This listener is spawned automatically — nothing to configure — but only under both of these conditions:
"tls": trueinconfig.json- at least one route in
routes.ymlhascertbot_renew: true
If neither condition is met, no second listener is started (a plain-HTTP main server already answers ACME challenges itself on whatever port it's already listening on, and there's no reason to bind port 80 at all if no vhost uses automatic renewal).
Bound while the process is still root, same as the main listener(s) — binding a port below 1024 needs that privilege. A bind failure here (port 80 already in use by something else, e.g. nginx or Apache also running on the same host) is logged as an error at startup, and renewal will keep failing with a connection error from Let's Encrypt until it's resolved — check for a port conflict with ss -tlnp | grep :80 if renewals fail right after this feature is enabled on a host that already runs other services.
Troubleshooting
| Symptom | Likely cause |
|---|---|
| Certificate never renews, no error visible | Check certbot_renew: true is actually set on a route for this vhost, and that vhost_cert has both cert and key pointing at real paths — a vhost with certbot_renew: true but no usable vhost_cert is skipped with a warning at scan time, not silently ignored, but the warning is easy to miss. |
Connection refused fetching the challenge URL |
Nothing is answering on port 80 at all — the classic signature of this is Connection refused specifically (not a timeout, which would suggest a firewall silently dropping packets instead). Confirm "tls": true and at least one certbot_renew: true route exist (both are required for the automatic port-80 listener to start — see above), then check ss -tlnp | grep :80 on the server itself. |
| Challenge still fails validation after confirming port 80 is listening | A firewall/router/security group is blocking port 80 from the public internet even though ProxyAuth itself is listening locally — confirm reachability from outside your network, not just curl localhost on the box itself. |
| "no HTTP-01 challenge offered" | Rare — would mean Let's Encrypt's API changed shape or an intermediate proxy is interfering with the ACME account/order requests themselves (not the challenge fetch). |
| "order did not become ready in time" | Let's Encrypt took longer than the built-in retry budget to validate — usually transient; the next scan interval will retry from scratch. |
| Account registration fails | Check directory_url is reachable from the server, and that account_credentials_path's parent directory is writable by the user ProxyAuth runs as. |
Certificate issuer still says (STAGING) after switching directory_url to production |
On a version that doesn't yet track which environment the saved account belongs to, delete account_credentials_path (default /etc/proxyauth/acme/account.json) and retry — this forces a fresh account registration against whatever directory_url is now configured. Current versions detect this automatically; no manual deletion needed. |
Permission denied (os error 13) persisting the account or certificate |
The directory (account_credentials_path's parent, or the vhost_cert directory) exists but isn't owned by/writable by whichever user actually runs the process (run_user in config.json, proxyauth by default) — chown -R it to that user. create_dir_all succeeding doesn't guarantee the current user can write into a directory that already existed with different ownership. |
Renewal failures are logged with the vhost name and the specific error — the currently valid certificate is never affected by a failed attempt, so a failure here is worth investigating but isn't an outage on its own.
See also
- TLS & Certificates - certificate loading, hot-reload mechanics, per-vhost certificates in general.
- routes.yml Reference § Virtual hosts - the
vhost,vhost_cert,certbot_renewfields. - config.json Reference - the
letsencryptblock. - CLI Reference §
proxyauth certbot renew- full flag reference for the manualrenew/check/newcommands.
📖 Wiki Home · 💻 Source Code · 🐛 Report an Issue · 📜 License
Found an error or something outdated on this page? Open an issue or submit a PR against the wiki repository.