Web / Caddy Server Interview questions
How do you set up a wildcard certificate in Caddy?
Wildcard certificates (like *.example.com) can only be validated with a DNS-01 ACME challenge, because a wildcard covers subdomains that don't correspond to a single reachable server for HTTP-01 validation. That means a DNS provider plugin, compiled in via xcaddy, is required.
xcaddy build --with github.com/caddy-dns/cloudflare
*.example.com, example.com { tls { dns cloudflare {env.CLOUDFLARE_API_TOKEN} } reverse_proxy localhost:4000 }
After building a custom binary with the relevant DNS module (Cloudflare in this example), the tls directive's dns subdirective tells Caddy to prove domain ownership by creating a temporary DNS TXT record through that provider's API rather than serving an HTTP response. The API token is best supplied through an environment variable placeholder rather than hardcoded in the Caddyfile. Once issued, the wildcard certificate covers every first-level subdomain, and Caddy renews it the same way as any other managed certificate.
More Related questions...