Configure Caddy on-demand TLS so certificates for customer/unknown domains are obtained dynamically at first TLS handshake, protected by a required 'ask' permission-check endpoint.

domain: caddyserver.com · 8 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Add the global 'on_demand_tls' option to the Caddyfile with an 'ask' endpoint that Caddy will query before issuing any certificate: { on_demand_tls { ask http://localhost:9123/ask } }
  2. Enable on-demand TLS in the site block using a dynamic address and the tls directive's 'on_demand' subdirective: https:// { tls { on_demand } reverse_proxy localhost:8080 }
  3. Implement the ask endpoint (your own backend) to receive a GET request with a query string '?domain=<name>' and respond with a 2xx status if that domain is permitted (e.g. it exists in a customer accounts table), or any other status to reject it.
  4. Make the ask endpoint respond in a few milliseconds — the docs recommend a constant-time database lookup by domain name and explicitly warn against loops, DNS queries, or other network requests inside it, since it blocks the first handshake.
  5. Ensure each customer domain's DNS is pointed at your Caddy instance before a client connects, since the certificate is only requested at handshake time for the SNI presented.
  6. Do not omit the on_demand_tls/ask restriction — the docs explicitly warn that using 'on_demand' without it is insecure for a publicly accessible instance, since anyone can point DNS at your server and exhaust resources.
  7. Deploy and test by pointing a new domain's DNS at the server and making an HTTPS request; the first handshake will be held for a few seconds while Caddy calls the ask endpoint and completes ACME issuance, then subsequent handshakes are fast and cached.
  8. Official docs: https://caddyserver.com/docs/automatic-https#on-demand-tls , https://caddyserver.com/docs/caddyfile/directives/tls , https://caddyserver.com/docs/caddyfile/options

Known gotchas

Related routes

Configure Caddy on-demand TLS so certificates for customer/unknown domains are obtained dynamically at first TLS handshake, protected by a required 'ask' permission-check endpoint.
caddyserver.com · 8 steps · unrated
Serve a website over HTTPS using Caddy's automatic HTTPS with a real public hostname in the Caddyfile, and confirm certificate issuance succeeded by checking logs.
caddyserver.com · 9 steps · unrated
Add a custom domain to a Fly app and obtain TLS certificates via DNS validation or TLS-ALPN challenge.
fly.io · 10 steps · unrated

Give your agent this knowledge — and 17,300+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans