To not leave any doubt, this what I have configured:
Caddyfile:
{
debug
auto_https prefer_wildcard
}
*.mydomain.net {
tls {
dns cloudflare {env.CLOUDFLARE_API_KEY}
}
}
serviceX.mydomain.net {
reverse_proxy <serviceX_ip>:<serviceX_port>
}
serviceY.mydomain.net {
reverse_proxy <serviceY_ip>:<serviceY_port>
}
Cloudflared:
tunnel: UUID
credentials-file: /etc/cloudflared/UUID.json
ingress:
- hostname: '*.mydomain.net'
service: https://<caddy_lxc_ip>:443
originRequest:
matchSNItoHost: true
- service: http_status:404
I’m able to access serviceX
once, but when I try to access serviceY
, my browser throws an HTTP ERROR 421, and this is what Caddy shows in the debug:
2025/02/27 19:47:07.785 DEBUG http.log.error strict host matching: TLS ServerName (serviceX.mydomain.net) and HTTP Host (serviceY.mydomain.net) values differ {"request": {"remote_ip": "<cloudflared_lxc_ip>", "remote_port": "41664", "client_ip": "<cloudflared_lxc_ip>", "proto": "HTTP/1.1", "method": "GET", "host": "serviceY.mydomain.net", "uri": "/", "headers": {"Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"], "Cache-Control": ["max-age=0"], "Cf-Visitor": ["{\"scheme\":\"https\"}"], "Accept-Encoding": ["gzip, br"], "Cf-Warp-Tag-Id": ["<cf-ward-tag-id>"], "Priority": ["u=0, i"], "Connection": ["keep-alive"], "Sec-Fetch-User": ["?1"], "Cdn-Loop": ["cloudflare; loops=1"], "Cf-Connecting-Ip": ["<cf-conneting-ip>"], "Sec-Fetch-Dest": ["document"], "User-Agent": ["Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Mobile Safari/537.36"], "Sec-Fetch-Site": ["none"], "Upgrade-Insecure-Requests": ["1"], "X-Forwarded-Proto": ["https"], "Sec-Ch-Ua": ["\"Not(A:Brand\";v=\"99\", \"Google Chrome\";v=\"133\", \"Chromium\";v=\"133\""], "Cf-Ray": ["<cf-ray>"], "Sec-Ch-Ua-Platform": ["\"Android\""], "Accept-Language": ["en-US,en;q=0.9"], "X-Forwarded-For": ["<x-forwarded-for-ip>"], "Sec-Fetch-Mode": ["navigate"], "Cf-Ipcountry": ["US"], "Sec-Ch-Ua-Mobile": ["?1"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "", "server_name": "serviceX.mydomain.net"}}, "duration": 0.000038972, "status": 421, "err_id": "jx0m9jf0t", "err_trace": "caddyhttp.(*Server).enforcementHandler (server.go:479)"}