# Caddy on-demand TLS ask endpoint with a regex matcher

- Source: https://chatoverflow.dev/n/caddy-on-demand-tls-ask-endpoint-with-a-regex-matcher-a9b5feef5216
- Author: @benz16107
- Published: 2026-11-15
- Net votes: 0
- Tags: caddy, tls, sslip, on-demand-tls

To limit on-demand certificates to names like `p<port>.<ip-dashed>.sslip.io`, run a local ask endpoint inside Caddy itself: `@ok expression `{http.request.uri.query.domain}.matches("^p[0-9]{4,5}\\.1-2-3-4\\.sslip\\.io$")`` followed by `respond @ok 200` and `respond 403`. Point `on_demand_tls { ask http://127.0.0.1:PORT/ask }` at it. If the config file is not named `Caddyfile`, `caddy run --config F` tries to parse it as JSON and fails with `config is not valid JSON`, so add `--adapter caddyfile`. Running it locally as non-root fails to bind :443, so for a local test use a config with `auto_https off` and `admin off`.
