Skip to main content
A Caddy proxy is one DNZ doesn’t run itself: a Caddy that DNZ configures the way it configures a Traefik, with the same routers, services and middlewares on the proxy’s page. Caddy’s built-in HTTP config loader (admin.config.load, module http) asks DNZ for its configuration every 10 seconds, and Caddy gets its certificates itself.
DNZ’s configuration replaces the Caddy’s whole configuration, Caddyfile sites included. To keep a Caddyfile and only get DNS records for its sites, use Caddy sites in DNS instead.
Caddy 2.7 or newer is needed (weighted round robin). Turn proxying on first, under Settings → Proxy. See Turning proxying on.

Setting it up

1

Open the setup guide

Go to Settings → Proxy → Add proxy and pick Caddy. Give the name and the addresses visitors reach it at. Everything in the setup is filled in, ready to copy as it is: New Caddy (Docker), Installed Caddy (systemd) or Just the file.
2

Check DNZ's address

DNZ address, as Caddy reaches it is filled in from your browser. Change it when Caddy reaches DNZ another way.A localhost address only works for a Caddy on the same machine. For one elsewhere, use DNZ’s LAN or public address and start DNZ with DNZ_HTTP_ADDR=0.0.0.0:8080, or put DNZ behind a reverse proxy. See HTTPS.
3

Start Caddy from dnz.json

Pick one of the ways below. Open ports 80 and 443 (and 443/udp for HTTP/3) to visitors.
4

Let it connect

A Caddy that calls from the addresses you gave connects as that proxy. From anywhere else, it shows up on the Proxy page as detected, to approve. See How DNZ recognizes a Caddy.
Every Caddy starts from the same small file, dnz.json, with the server’s connect key:
dnz.json
The loader asks GET /api/proxy/caddy 10 seconds (load_delay) after each load. Each configuration DNZ sends names the loader again, so Caddy keeps asking.
Put dnz.json next to this file and run docker compose up -d:
docker-compose.yml
The setup guide’s one command writes both files to ~/caddy and starts Caddy.

How DNZ recognizes a Caddy

A Caddy is recognized and approved exactly like a Traefik:
  • by the address it calls from: one of the proxy’s addresses, or its Calls DNZ from;
  • a Caddy from any other address shows up on the Proxy page as detected and waits until you approve, link or ignore it;
  • several Caddies behind one address give each a name on the URL: http://DNZ-ADDRESS:8080/api/proxy/caddy?name=edge-1;
  • a proxy can get a token of its own (⋯ → Use a token of its own), which then goes in the Authorization header instead of the connect key.
See How DNZ recognizes a Traefik for the details. While a Caddy isn’t approved, or proxying is off, it gets a configuration with no sites and drops what it had. On its card, a proxy’s dot turns green (Connected) once it has fetched its configuration in the last minute.

What Caddy gets

DNZ translates the proxy’s routers, services and middlewares into Caddy’s own JSON configuration.
  • HTTPS routers go to a Caddy server on :443, where Caddy gets the certificates itself (automatic HTTPS, Let’s Encrypt or ZeroSSL). A router’s certificate resolver isn’t used.
  • Certificates uploaded to the proxy (TLS → Certificates) are loaded into Caddy.
  • Wildcard hosts need Caddy built with a DNS provider module, or an uploaded certificate.
  • Other routers go to a server on :80, which also answers Caddy’s HTTP-01 challenges.
  • Caddy’s own HTTP→HTTPS redirects are off. An HTTP router with a redirect middleware does that, as with Traefik; Add route makes both in one step.
  • The entry points of a Caddy proxy are web (:80) and websecure (:443).
  • Order: exact hosts before wildcards, longer path prefixes first, and a set priority before all of it. A request no route takes gets a 404.

Left out

These are left out, with a warning on the proxy’s page:

Trying the endpoint by hand

Run this from the Caddy’s machine, so DNZ recognizes it by that address:
It returns the same configuration Caddy gets. A superadmin can also look at what a Caddy proxy gets, and its warnings, with GET /api/proxies/{id}/caddy or dnz proxy caddy <proxy>. See the Proxy API.

Troubleshooting

The Caddy hasn’t fetched its configuration in the last minute. Check that it started from dnz.json (not the Caddyfile), that it can reach DNZ’s HTTP address (a localhost address only works on the same machine), that the file has the current connect key, and look on the Proxy page for a detected Caddy: it may be calling from an address DNZ doesn’t know yet.
DNZ’s configuration replaces the Caddy’s whole configuration. Move those sites into routers on the proxy’s page, or keep the Caddyfile and use Caddy sites in DNS instead.
Caddy needs a DNS challenge for a wildcard certificate, so it must be built with a DNS provider module. Otherwise, upload the certificate to the proxy under TLS → Certificates.
It may be one Caddy can’t take. The proxy’s page lists what was left out, and why.

Next steps

Routers, services and middlewares

Set up what each Caddy serves.

Caddy sites in DNS

Keep your Caddyfile and only get DNS records for its sites.