- The problem I’m having:
I want specific subdomains to be either IPv4 or IPv6 only.
My overall goal is that I run a service that relies on the X-Forwarded-For header to show the client’s IP address. My server has both IPv4 and IPv6, but Caddy always forwards the IPv6 address when it’s available. I need to be able to access the client’s IPv4 as well, without disabling IPv6 entirely. So I want to make dedicated v4/v6 subdomains but I don’t know how…
- Error messages and/or full log output:
I can’t provide logs for it, since I can’t figure out how can I even do this. Currently everything responds to both v4 and v6.
- Caddy version:
caddy version
v2.10.0
- How I installed and ran Caddy:
I used xcaddy to build it with caddy-dns/cloudflare.
xcaddy build --with github.com/caddy-dns/cloudflare
a. System environment:
Debian 12 (Linux x86_64), with systemd – no docker.
Domain: (*.)example.com
b. Command:
c. Service/unit/compose file:
cat /lib/systemd/system/caddy.service
[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target
[Service]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/local/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/local/bin/caddy reload --config /etc/caddy/Caddyfile --force
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE
Environment="CLOUDFLARE_API_KEY=REDACTED"
Restart=on-failure
RestartSec=5s
d. My complete Caddy config:
caddy fmt /etc/caddy/Caddyfile
(cf) {
tls {
dns cloudflare {env.CLOUDFLARE_API_KEY}
}
}
*.demo.example.com {
import cf
@demo host app.demo.example.com
handle @demo {
reverse_proxy 10.0.0.10:3006
}
handle {
abort
}
}
example.com {
import cf
reverse_proxy 10.0.0.14:3000
}
.example.com {
import cf
import sites/
handle {
redir https://example.com permanent
}
}
Example from my sites/ directory:
cat /etc/caddy/sites/service.example.com
@service host service.example.com
handle @service {
reverse_proxy 10.0.0.10:8002
}
- Links to relevant resources: