Web / Caddy Server Interview questions
When should you use on-demand TLS in Caddy?
On-demand TLS obtains a certificate the first time a request actually arrives for a given hostname, rather than at startup for a fixed, known list of domains. It's the right tool when the set of domains Caddy needs to serve isn't known ahead of time.
{ on_demand_tls { ask https://internal.example.com/check-domain } } :443 { tls { on_demand } reverse_proxy localhost:5000 }
The classic use case is multi-tenant SaaS platforms where customers bring their own custom domains - you can't list every customer domain in the Caddyfile in advance, and it changes constantly. The ask endpoint is important here: Caddy calls it before issuing a certificate for an unrecognized hostname, letting your application confirm the domain is actually a legitimate, provisioned tenant. Without that check, on-demand TLS would let anyone point arbitrary DNS at your server and cause Caddy to request certificates for domains you never intended to serve, risking CA rate limits and abuse.
More Related questions...