This episode covers wildcard certificates and the DNS-01 challenge: wildcard syntax, the DNS-01 requirement for wildcards, DNS provider credentials like Cloudflare and Route53, custom builds with xcaddy, and per-site and global configuration.

Sometimes you need a single certificate protecting all of your subdomains: app.example.com, api.example.com, blog.example.com, and so on. That's where a wildcard certificate comes in. Unfortunately, wildcards can only be obtained through the DNS-01 challenge — because verification must go through a DNS TXT record, not HTTP.
Episode 9 covers how Caddy manages wildcard certificates. You'll learn wildcard syntax in the Caddyfile, why DNS-01 is the only way, how to configure DNS providers like Cloudflare and Route53, and how to build a custom Caddy binary with xcaddy to add DNS provider modules.
This is also the first episode involving plugins — a concept that becomes a major theme in episode 29. Prepare your DNS provider's API credentials if you want to practice hands-on.
A wildcard certificate covers all subdomains at one level:
*.example.com {
root * /var/www/sites/{host}
file_server
}The *.example.com block serves app.example.com, api.example.com, and others. Caddy will issue a certificate for *.example.com — a single certificate valid for all those subdomains.
Important to understand:
*.example.com does not cover a.b.example.com.example.com itself needs an additional certificate.A common combination: create two certificates — one for the root example.com and one for *.example.com.
The HTTP-01 challenge needs port 80 publicly accessible for each subdomain — impractical for dozens of subdomains. DNS-01 solves it differently:
_acme-challenge.example.com containing the token.Because verification goes through DNS, it doesn't matter how many subdomains there are — a single record is enough for a wildcard.
With the DNS provider module installed, Caddy creates and deletes TXT records automatically using your API credentials. You never touch the DNS panel manually.
DNS provider modules read credentials from environment variables. Example for Cloudflare:
export CF_API_TOKEN=your_token
export CF_ZONE=example.com
caddy run --config CaddyfileEach provider has its own variables — check the module's documentation. Never write tokens in the Caddyfile; always use environment variables.
Set a global provider so all sites use it:
{
acme_dns cloudflare {env.CF_API_TOKEN}
}
*.example.com {
root * /var/www
file_server
}acme_dns cloudflare ... uses Cloudflare for all DNS challenges across every site.
Combine per-site providers and fallbacks:
a.example.com {
tls {
dns cloudflare {env.CF_API_TOKEN}
}
}
b.example.com {
tls {
dns digitalocean {env.DO_API_TOKEN}
}
}Site A uses Cloudflare, site B uses DigitalOcean. Each provider requires a Caddy binary built with its corresponding module.
DNS provider modules aren't in the standard binary. To add them, use xcaddy:
go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
xcaddy build --with github.com/caddy-dns/cloudflarexcaddy build --with ... creates a new Caddy binary that includes the Cloudflare DNS module.
Modules can be combined in a single build:
xcaddy build \
--with github.com/caddy-dns/cloudflare \
--with github.com/caddy-dns/digitalocean \
--with github.com/mholt/caddy-l4The result is a custom binary with all those modules. Store this binary on your server and use it in place of the standard caddy. Always track module versions when updating the binary — plugins must be compatible with your Caddy version.
_acme-challenge record.Episode 9 opened the door to wildcard certificates: *.example.com syntax in the Caddyfile, the DNS-01 challenge requirement for wildcards, DNS provider credentials like Cloudflare and Route53 via environment variables, global and per-site configuration, and custom builds with xcaddy.
Key takeaways:
acme_dns cloudflare {env.CF_API_TOKEN} sets a global provider.xcaddy build --with.In the next episode, episode 10, we'll cover custom certificates and internal CA — manual certificates and PEM chains, private CAs with self-signed certs, client certificates for mTLS, Step CA and internal ACME server integration, and on-demand TLS for multi-tenancy. Advanced certificate control awaits.