I am running Traefik 2.5.6 on Docker 19.03.02. I have Traefik proxying many containers all configured with labels that I can access through HTTPS (Let's Encrypt) but I have one, homeassistant
, that is consistently failing with a 400 Bad Request.
What is frustrating is that I can see the request to homeassistant
in the Traefik logs with a 400 status code but when run a shell in the Traefik container, I can curl
the same URL successfully. The only middleware I have is an HTTP to HTTPS redirect but I am trying the HTTPS endpoint directly.
When I try to access Home Assistant from my desktop, I get a 400 following redirects and not following redirects.
curl -L -o /dev/null -w "\nStatus: %{http_code}\n" https://homeassistant.example.com
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 16 100 16 0 0 219 0 --:--:-- --:--:-- --:--:-- 219
Status: 400
I check the Traefik logs at debug level and see the following entries.
time="2022-01-15T14:52:59-05:00" level=debug msg="vulcand/oxy/roundrobin/rr: begin ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\",\"RawFragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"*/*\"],\"User-Agent\":[\"curl/7.64.1\"],\"X-Forwarded-Host\":[\"homeassistant.example.com\"],\"X-Forwarded-Port\":[\"443\"],\"X-Forwarded-Proto\":[\"https\"],\"X-Forwarded-Server\":[\"d1a28518adcc\"],\"X-Real-Ip\":[\"192.168.1.110\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"homeassistant.example.com\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"192.168.1.110:52736\",\"RequestURI\":\"/\",\"TLS\":null}"
time="2022-01-15T14:52:59-05:00" level=debug msg="vulcand/oxy/roundrobin/rr: Forwarding this request to URL" ForwardURL="http://172.18.0.25:8123" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\",\"RawFragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"*/*\"],\"User-Agent\":[\"curl/7.64.1\"],\"X-Forwarded-Host\":[\"homeassistant.example.com\"],\"X-Forwarded-Port\":[\"443\"],\"X-Forwarded-Proto\":[\"https\"],\"X-Forwarded-Server\":[\"d1a28518adcc\"],\"X-Real-Ip\":[\"192.168.1.110\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"homeassistant.example.com\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"192.168.1.110:52736\",\"RequestURI\":\"/\",\"TLS\":null}"
time="2022-01-15T14:52:59-05:00" level=debug msg="vulcand/oxy/roundrobin/rr: completed ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\",\"RawFragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"*/*\"],\"User-Agent\":[\"curl/7.64.1\"],\"X-Forwarded-Host\":[\"homeassistant.example.com\"],\"X-Forwarded-Port\":[\"443\"],\"X-Forwarded-Proto\":[\"https\"],\"X-Forwarded-Server\":[\"d1a28518adcc\"],\"X-Real-Ip\":[\"192.168.1.110\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"homeassistant.example.com\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"192.168.1.110:52736\",\"RequestURI\":\"/\",\"TLS\":null}"
192.168.1.110 - - [15/Jan/2022:19:52:59 +0000] "GET / HTTP/2.0" 400 16 "-" "-" 70 "homeassistant-secure@docker" "http://172.18.0.25:8123" 6ms
I copy the URL from the logs and run a shell in the Traefik container and get a 200 if I follow redirects and a 302 if I don't.
docker exec -it traefik sh
apk --no-cache add curl
curl -L -o /dev/null -w "\nStatus: %{http_code}\n" http://172.18.0.25:8123
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 2822 100 2822 0 0 265k 0 --:--:-- --:--:-- --:--:-- 265k
Status: 200
Here are the Traefik labels. I included Portainer since that does work and I can't see how they are different.
docker inspect homeassistant portainer | jq '.[].Config.Labels' | grep traefik
"traefik.docker.network": "frontend",
"traefik.enable": "true",
"traefik.http.middlewares.homeassistant-https-redirect.redirectscheme.scheme": "https",
"traefik.http.routers.homeassistant-secure.entrypoints": "https",
"traefik.http.routers.homeassistant-secure.rule": "Host(`homeassistant.example.com`)",
"traefik.http.routers.homeassistant-secure.service": "homeassistant",
"traefik.http.routers.homeassistant-secure.tls": "true",
"traefik.http.routers.homeassistant-secure.tls.certresolver": "cloudflare",
"traefik.http.routers.homeassistant.entrypoints": "http",
"traefik.http.routers.homeassistant.middlewares": "homeassistant-https-redirect",
"traefik.http.routers.homeassistant.rule": "Host(`homeassistant.example.com`)",
"traefik.http.services.homeassistant.loadbalancer.server.port": "8123"
"traefik.docker.network": "proxy",
"traefik.enable": "true",
"traefik.http.middlewares.portainer-https-redirect.redirectscheme.scheme": "https",
"traefik.http.routers.portainer-secure.entrypoints": "https",
"traefik.http.routers.portainer-secure.rule": "Host(`portainer.example.com`)",
"traefik.http.routers.portainer-secure.service": "portainer",
"traefik.http.routers.portainer-secure.tls": "true",
"traefik.http.routers.portainer-secure.tls.certresolver": "cloudflare",
"traefik.http.routers.portainer.entrypoints": "http",
"traefik.http.routers.portainer.middlewares": "portainer-https-redirect",
"traefik.http.routers.portainer.rule": "Host(`portainer.example.com`)",
"traefik.http.services.portainer.loadbalancer.server.port": "9000"
They are on the same network, frontend
.
docker inspect traefik homeassistant portainer | jq '[ .[] | {Name: .Name, NetworkMode: .HostConfig.NetworkMode } ]'
[ {
"Name": "/traefik",
"NetworkMode": "frontend"
}, {
"Name": "/homeassistant",
"NetworkMode": "frontend"
}, {
"Name": "/portainer",
"NetworkMode": "frontend"
} ]
The all have IP address in the same 172.18.0.0/16
subnet.
docker inspect traefik homeassistant portainer | jq '[ .[] | {Name: .Name, IPAddress: .NetworkSettings.Networks.frontend.IPAddress } ]'
[ {
"Name": "/traefik",
"IPAddress": "172.18.0.4"
}, {
"Name": "/homeassistant",
"IPAddress": "172.18.0.25"
}, {
"Name": "/portainer",
"IPAddress": "172.18.0.7"
} ]
Thanks for the help. It must be something simple since I have over 20 containers configured similarly and successfully using Ansible but I have been at this for more than a week and getting nowhere.
Wes.