Docker Hub - Quay.io - bfren ecosystem
A reverse proxy for your other containers, built on Caddy and configured using one simple JSON file. Caddy requests and renews Let's Encrypt certificates automatically, using the HTTP challenge or the DNS challenge (via Hetzner) for wildcards and private servers.
It is built on Alpine + S6, and adds:
bf-proxy, a Nushell module that turns conf.json into Caddy's JSON configuration, with secure defaultsThis is the successor to bfren/nginx-proxy - see Migrating from nginx-proxy.
docker-compose.yml:
services:
proxy:
image: quay.io/bfren/caddy-proxy:2.0
restart: unless-stopped
ports:
- "0.0.0.0:80:80"
- "0.0.0.0:443:443"
- "0.0.0.0:443:443/udp"
environment:
- BF_PROXY_DOMAIN=proxy.example.com
- [email protected]
- BF_PROXY_LETS_ENCRYPT_LIVE=0
volumes:
- ./ssl:/ssl
- ./sites:/sites
- ./www:/www
app:
image: traefik/whoami
This example is also in docker-compose.yml.
ssl/conf.json:
{
"$schema": "https://schemas.bfren.dev/docker/caddy-proxy/domains/2026-11.json",
"domains": [
{ "primary": "app.example.com", "aliases": [ "www.app.example.com" ], "upstream": "http://app:80" }
]
}
proxy.example.com, app.example.com and www.app.example.com at your server.docker compose up -d, then check docker compose logs proxy for errors.BF_PROXY_LETS_ENCRYPT_LIVE=1 and run docker compose up -d again.Until step 3, certificates come from Let's Encrypt's staging server, so browsers warn that they aren't trusted. Staging is used first because the live server is rate limited, and failed attempts while you set things up count towards the limit.
conf.json file, with a JSON schema for validation and autocompletewww (UID 1000), not rootImages are published to Docker Hub (bfren/caddy-proxy) and Quay.io (quay.io/bfren/caddy-proxy) for linux/amd64, linux/arm/v7 and linux/arm64.
| Tag | Example | Use when |
|---|---|---|
latest | You always want the newest image | |
MAJOR | 2 | You want updates, but not breaking changes |
MINOR | 2.0 | You want fixes only - recommended |
VERSION | 2.0.5 | You want to pin this image exactly |
A new MAJOR version means a breaking change. Before moving to one, read the changelog, where each breaking change is marked Breaking.
| Port | Purpose |
|---|---|
80 | HTTP challenge, and redirecting HTTP to HTTPS |
443 | HTTPS |
443/udp | HTTP/3 (optional) |
Caddy runs as www and needs no extra capabilities: Docker lets unprivileged users bind to ports below 1024 inside a container. With network_mode: host the host's setting applies instead, so set net.ipv4.ip_unprivileged_port_start=80 (or lower) on the host.
| Volume | Purpose |
|---|---|
/ssl | conf.json, users.json (basic auth), and Caddy's certificates (/ssl/caddy). |
/sites | Per-domain Caddy configuration - see below. |
/www | /www/public is served for BF_PROXY_DOMAIN, with the maintenance page. |
Everything in the volumes is owned by www (UID / GID 1000), and /ssl is readable only by its owner. On the host, edit the files as UID 1000 (usually the first user account) or with sudo.
| Variable | Values | Description | Default |
|---|---|---|---|
BF_PROXY_DOMAIN | domain | Required. The proxy's domain - unknown hosts redirect here. | |
BF_PROXY_LETS_ENCRYPT_EMAIL | Required. Let's Encrypt account email. | ||
BF_PROXY_LETS_ENCRYPT_LIVE | 0, 1 | Use the live server - 0 uses staging. | 0 |
BF_PROXY_USE_INTERNAL_CA | 0, 1 | Use Caddy's internal (untrusted) CA - for testing. | 0 |
BF_PROXY_ACME_CHALLENGE | http, dns | Default challenge - can be set per domain. | http |
BF_PROXY_DNS_PROVIDER | hetzner | DNS provider for the DNS challenge. | hetzner |
BF_PROXY_HETZNER_TOKEN | token | Hetzner API token for the DNS challenge. | |
BF_PROXY_DNS_TTL | duration | TTL of DNS challenge records, e.g. 60s. | provider's |
BF_PROXY_DNS_PROPAGATION_DELAY | duration | Wait before a DNS challenge record is checked. | 60s |
BF_PROXY_DNS_PROPAGATION_TIMEOUT | duration | How long to wait for DNS propagation, e.g. 5m. | |
BF_PROXY_DNS_RESOLVERS | IPs | Space-separated resolvers to check propagation. | |
BF_PROXY_DNS_OVERRIDE_ZONE | domain | Delegate DNS challenges to <primary>.<zone>. | |
BF_PROXY_SSL_REDIRECT_TO_CANONICAL | 0, 1 | Default for redirectToPrimary. | 0 |
BF_PROXY_UPSTREAM_RETRY | duration | Default for retry (0s to disable). | 5s |
BF_PROXY_AUTO_RELOAD | 0, 1 | Regenerate and reload when configuration changes. | 0 |
BF_PROXY_HARDEN | 0, 1 | Allow only TLS 1.3 (older devices may fail). | 0 |
BF_PROXY_BLOCK_AI_BOTS | 0, 1 | Return 403 to AI training crawlers. | 1 |
BF_PROXY_ACCESS_LOG | 0, 1 | Write access logs to the container output. | 0 |
BF_PROXY_CLEAN_INSTALL | 0, 1 | Delete all configuration and certificates on start. | 0 |
BF_PROXY_AUTO_PRIMARY | domain | With BF_PROXY_AUTO_UPSTREAM, generate a missing conf.json. | |
BF_PROXY_AUTO_UPSTREAM | URL | Upstream for the generated domain. | |
BF_PROXY_AUTO_ALIASES | names | Aliases for the generated domain. | |
BF_PROXY_AUTO_CUSTOM | 0, 1 | Mark the generated domain as custom. | 0 |
BF_PROXY_MAINTENANCE_REFRESH_SECONDS | integer | Maintenance page refresh interval. | 6 |
See Alpine + S6 for BF_DEBUG, BF_TZ and the other base image variables.
| Argument | Description | Default |
|---|---|---|
CADDY_VERSION | Caddy release to build. | 2.11.9 |
CADDY_HETZNER_VERSION | caddy-dns/hetzner release. | 2.0.1 |
CADDY_BUILDER | xcaddy build image. | quay.io/bfren-bin/caddy:2.11-builder-alpine |
AI_ROBOTS_VERSION | ai.robots.txt release. | v2.0 |
On start-up, conf.json is read (or converted from nginx-proxy format, or generated from the BF_PROXY_AUTO_* variables), checked, and turned into one Caddy configuration file. Each domain's part is kept in /sites/<primary>.json. Caddy then runs under S6. The health check uses a server on 127.0.0.1:2020 with no access log, so it doesn't fill the container log.
Domains are defined in /ssl/conf.json - see proxy-conf-sample.json for an example and the schema for the full definition. Add $schema (as in the Quickstart) for validation and autocomplete.
| Property | Description |
|---|---|
primary | Required. The primary domain name. |
aliases | Other host names - wildcards need the DNS challenge. |
upstream | Required (unless custom). e.g. http://app:5000 - a list load balances. |
lb | Load balancing policy (default random) - see below. |
retry | How long to retry an unreachable upstream, e.g. 10s. |
challenge | http or dns - defaults to BF_PROXY_ACME_CHALLENGE. |
dnsOverrideDomain | Where to create DNS challenge records ("" to disable). |
redirectToPrimary | Redirect aliases to the primary domain. |
auth | Basic auth: false (default), true for all users, or a list of names. |
headers | Response headers to add or override - null stops the proxy adding one. |
routes | Extra routes, before the default upstream - see below. |
compress | false to turn off compression. |
clacks | false to remove the X-Clacks-Overhead header. |
tlsSkipVerify | true to accept self-signed https upstreams. |
custom | See below. |
lb can be random, round_robin, least_conn, first, ip_hash, uri_hash or client_ip_hash.
Each route can have a path (e.g. /api/* - without one it matches everything) and exactly one action:
| Action | Description |
|---|---|
upstream | Proxy here (or a list, with lb). stripPrefix removes a prefix. |
redirect | Redirect here (301, or set status). Caddy placeholders work. |
root | Serve static files from this (mounted) directory. |
"routes": [
{ "path": "/api/*", "upstream": [ "http://api1:8080", "http://api2:8080" ], "lb": "round_robin", "stripPrefix": "/api" },
{ "path": "/old/*", "redirect": "https://example.com/new{http.request.uri.path}" },
{ "path": "/files/*", "root": "/www/files" }
]
For every domain:
Strict-Transport-Security, X-Frame-Options, X-Content-Type-Options and Referrer-Policy are added, and X-Clacks-Overhead: GNU Terry Pratchett - because he was a legend.
To stop one being added, set it to null in the domain's headers - e.g. "X-Frame-Options": null for Vaultwarden, which sets it itself.X-Real-IP and Caddy's X-Forwarded-* headers are sent upstream. WebSockets work automatically.retry, so a quick restart isn't noticed), or returns 502, 503 or 504, an auto-refreshing maintenance page is shown. It is regenerated on every start, so don't edit /www/public/maintenance.html. index.html is only created when /www/public doesn't exist, so your own is kept.BF_PROXY_DOMAIN, which serves /www/public (static files cached for a year, /favicon.ico returning 204 unless you add one).With BF_PROXY_BLOCK_AI_BOTS=1, crawlers that collect AI training data get 403 Forbidden. The list comes from ai.robots.txt when the image is built, keeping only crawlers whose function is training data collection - AI search crawlers, assistants and user-triggered agents (e.g. OAI-SearchBot, ChatGPT-User) are not blocked. It is saved to /usr/share/caddy-proxy/ai-bots.txt.
Each domain's Caddy configuration is generated into /sites/<primary>.json: its route, its errors route (the maintenance page) and its tls policy (including the ACME challenge). The file is regenerated on every start and by proxy-regenerate, so don't edit it. Instead, either add your own routes to it, or take it over with custom.
/sites/<primary>.d, e.g. /sites/app.example.com.d.*.json files to it, each holding a Caddy route or an array of routes.proxy-regenerate.Your routes go after the security headers and basic auth, so they are protected like the rest of the site, and before routes and the default upstream.
A file ending .before.json goes first instead - before alias redirects, AI bot blocking, security headers, compression and basic auth. Use it only for a route that must not be protected, e.g. a public /health endpoint on a site that otherwise needs a login. A warning is logged when one is loaded.
Files load in natural sort order, so use lower case names with a two-digit prefix, e.g. 10-health.before.json, 20-api.json. Nginx *.conf files from nginx-proxy are ignored, with a warning.
Set "custom": true on the domain. Its file is generated once if it doesn't exist, then left alone, so you can edit it. To regenerate it from conf.json, run proxy-regenerate -d <primary> -f.
Use the DNS challenge for wildcard aliases, and for servers that are not reachable from the internet (e.g. only over a VPN).
In the Hetzner Console project that holds your zones, create an API token with read / write permission (the module uses the Cloud DNS API).
Set BF_PROXY_HETZNER_TOKEN to the token - see keeping the token out of your compose file. It is never written to the generated configuration: Caddy reads it from the environment.
Set BF_PROXY_ACME_CHALLENGE=dns, or "challenge": "dns" on each domain.
Optionally, set BF_PROXY_DNS_TTL=60s (Hetzner's lowest), so old challenge values aren't cached for long.
After creating each record, Caddy waits BF_PROXY_DNS_PROPAGATION_DELAY (60 seconds) before asking Let's Encrypt to check it. Without the wait, Let's Encrypt may ask a Hetzner nameserver that doesn't have the record yet, and the "not found" answer is cached, so retries fail too. (Caddy's own check passes as soon as one nameserver has the record, which isn't enough.) The wait only happens when a certificate is issued or renewed, and certificates are requested in parallel, so the waits overlap.
The Hetzner token can only create records in zones Hetzner hosts. For a domain hosted anywhere else, point its _acme-challenge records at a zone Hetzner does host, and tell Caddy to create the records there:
acme.example.net. It can be a separate domain using Hetzner's nameservers, or a subdomain of yours delegated to Hetzner with NS records.BF_PROXY_DNS_OVERRIDE_ZONE=acme.example.net.Each domain in conf.json gets one name in the zone - its primary, e.g. send.example.com.acme.example.net - and every host name in the domain points to it, aliases included. With BF_PROXY_ACME_CHALLENGE=dns the proxy domain needs one too.
For example, with BF_PROXY_DOMAIN=proxy.example.com and this domain:
{ "primary": "send.example.com", "aliases": ["www.send.example.com", "*.files.example.com"], "upstream": "http://app:80" }
| CNAME record | Value |
|---|---|
_acme-challenge.proxy.example.com | proxy.example.com.acme.example.net. |
_acme-challenge.send.example.com | send.example.com.acme.example.net. |
_acme-challenge.www.send.example.com | send.example.com.acme.example.net. |
_acme-challenge.files.example.com | send.example.com.acme.example.net. |
_acme-challenge. then the host name, without the *. for a wildcard.Per domain, "dnsOverrideDomain" changes this:
"" - for a domain Hetzner hosts directly. It needs no CNAME records. (The proxy domain always uses the zone while it is set.)send.acme.example.net - use that name instead of <primary>.<zone>.A wildcard and the same name without *. (e.g. *.files.example.com and files.example.com) share one CNAME record, so they can't point to different names - put them in the same domain.
Check the records before requesting certificates:
dig +short CNAME _acme-challenge.send.example.com # send.example.com.acme.example.net.
dig +short NS acme.example.net # Hetzner's nameservers
Or run proxy-dns, which looks up public DNS (using Google's DNS-over-HTTPS, as Let's Encrypt sees it) for every host name, including the proxy domain, and checks:
_acme-challenge.<host> is a CNAME to the override domain when one is set, and is not a CNAME when it isn't.letsencrypt.org (issuewild for wildcards).It does nothing when BF_PROXY_USE_INTERNAL_CA=1, and exits 1 if anything would stop a certificate being issued.
Run proxy-regenerate after changing conf.json, users.json or files in /sites, or set BF_PROXY_AUTO_RELOAD=1 to do it automatically. Files are checked every 5 seconds, and once they have been unchanged for 5 seconds configuration is regenerated and Caddy reloads without dropping connections.
If the new configuration is not valid, the errors are written to the container log and Caddy keeps running with the current configuration.
Run these with docker exec <container> <command>, e.g. docker exec proxy proxy-certs.
| Command | Description |
|---|---|
proxy-regenerate | Regenerate configuration from conf.json and reload Caddy. |
proxy-regenerate -d <primary> | Only regenerate that domain's file. |
proxy-regenerate -d <primary> -f | Regenerate that domain's file, even with "custom": true. |
proxy-reload | Validate the current configuration and reload Caddy. |
proxy-validate | Validate conf.json and the current Caddy configuration. |
proxy-certs | List certificates and days left (flagged at 14 or fewer). |
proxy-renew -a | Delete all certificates and restart Caddy, so it requests new ones. |
proxy-renew -d <primary> | The same, for one domain (its primary and aliases). |
proxy-pem | Write the PEM files now. |
proxy-cleanup | List domains no longer in conf.json - deletes nothing. |
proxy-cleanup -l | Delete those domains' configuration and certificates. |
proxy-token | Check the Hetzner token works and can manage your zones. |
proxy-dns | Check the public DNS records each host name needs (see above). |
proxy-adduser <username> <password> | Add a basic auth user, or change their password. |
proxy-deluser <username> | Remove a basic auth user. |
Passwords are stored as bcrypt hashes, but proxy-adduser takes the password as an argument, so it may be saved in your shell history.
/ssl/conf.json to the new /ssl volume - it is converted on start-up. The original is kept as /ssl/conf.json.nginx-proxy, and anything that can't be converted is reported in the log.quay.io/bfren/caddy-proxy and rename variables from PROXY_* to BF_PROXY_* (old names are ignored). These are no longer used: PROXY_ENABLE_AUTO_UPDATE (Caddy renews automatically), PROXY_ENABLE_NAXSI, PROXY_SSL_KEY_BITS, PROXY_SSL_DHPARAM_BITS, PROXY_GETSSL_SKIP_HTTP_TOKEN_CHECK and PROXY_UPSTREAM_DNS_RESOLVER./sites can't be converted - rewrite it as Caddy JSON in /sites/<primary>.d.BF_PROXY_LETS_ENCRYPT_LIVE=0 until everything works.nginx-adduser is replaced by proxy-adduser -Content type
Image
Digest
sha256:485765903…
Size
43.4 MB
Last updated
1 day ago
docker pull bfren/caddy-proxy