This Caddy module implements a DNSLink resolver that routes requests to different reverse proxies based on the content of _dnslink TXT records.
More information about the DNSLink specification can be found here: https://dnslink.dev
- Looks up
_dnslink.<host>TXT records. - Parses
dnslink=<value>. - Matches the value against configured prefixes.
- Rewrites the request path by prepending the DNSLink value.
- Proxies the request to the configured upstream.
- Caches DNS lookups.
To build Caddy with this module, use xcaddy:
xcaddy build \
--with github.com/o8is/caddy-dnslinkTo build with local changes:
xcaddy build \
--with github.com/o8is/caddy-dnslink=.You can use the pre-built image ghcr.io/o8is/caddy-dnslink.
To run the image with your own Caddyfile, mount it as a volume:
docker run -d \
-p 80:80 \
-p 443:443 \
-v $(pwd)/Caddyfile:/etc/caddy/Caddyfile \
ghcr.io/o8is/caddy-dnslinkTo create a custom Docker image with your Caddyfile baked in, you can copy the Caddy binary from the image:
FROM ghcr.io/o8is/caddy-dnslink AS source
FROM caddy:2.7.5
COPY --from=source /usr/bin/caddy /usr/bin/caddy
COPY Caddyfile /etc/caddy/CaddyfileThen build and run your custom image:
docker build -t my-caddy-dnslink .
docker run -d -p 80:80 -p 443:443 my-caddy-dnslinkIf you want to build the image yourself:
docker build -t caddy-dnslink .{
order dnslink before reverse_proxy
}
:80 {
dnslink {
proxies {
# prefix [replacement] upstream
/swarm /bzz varnish:8080
/arweave / ar:4000
/ipfs ipfs:8080
}
cache_ttl 5m
}
}{
"handler": "dnslink",
"upstreams": {
"/swarm": "varnish:8080",
"/arweave": "ar:4000",
"/ipfs": "ipfs:8080"
},
"replacements": {
"/swarm": "/bzz",
"/arweave": "/"
},
"cache_ttl": 300000000000
}- A request comes in for
example.com. - The module looks up
TXT _dnslink.example.com. - Suppose it returns
dnslink=/swarm/1234.... - The module checks if
/swarmis in theproxieslist. - It finds
varnish:8080. - It rewrites the request path to
/bzz/1234...(plus the original path). - It proxies the request to
varnish:8080.