You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Traefik无法将部分容器路由至正确后端的问题排查

Alright, let's figure out why HomeAssistant is throwing a 404 while Portainer works perfectly with Traefik. I've dealt with this exact issue a few times, so here are the key areas to check, ordered by likelihood:

1. Double-Check HomeAssistant's Traefik Labels

Since Portainer is routing correctly, its labels are set up properly—so the problem is almost certainly a mismatch in HomeAssistant's labels. Here's what to verify:

  • Missing or incorrect traefik.enable=true: If Traefik has exposedByDefault=false in its config (which is a best practice), you need to explicitly enable routing for each container. Portainer has this label, but HomeAssistant might not.
  • Wrong host rule: Make sure traefik.http.routers.homeassistant.rule uses the correct domain (e.g., Host(homeassistant.yourdomain.com)). Typos here (like a missing dot or misspelled domain) will cause Traefik to ignore the request, leading to a 404.
  • Incorrect backend port: HomeAssistant runs on port 8123 by default—confirm traefik.http.services.homeassistant.loadbalancer.server.port=8123 is set. If you put the wrong port here, Traefik can't reach the service.

Here's an example of properly formatted labels for HomeAssistant:

labels:
  - "traefik.enable=true"
  - "traefik.http.routers.homeassistant.rule=Host(`homeassistant.yourdomain.com`)"
  - "traefik.http.routers.homeassistant.entrypoints=websecure"
  - "traefik.http.routers.homeassistant.tls.certresolver=letsencrypt"
  - "traefik.http.services.homeassistant.loadbalancer.server.port=8123"
  - "traefik.docker.network=traefik-proxy"

2. Verify Docker Network Alignment

Traefik can only route to containers on the same Docker network. Portainer works, so it's already connected to Traefik's network—check if HomeAssistant is too:

  • Look at your docker-compose.yml for both services: ensure HomeAssistant uses the same network as Traefik (e.g., a dedicated traefik-proxy network).
  • Run docker inspect homeassistant and docker inspect traefik to confirm they share at least one network. If not, add HomeAssistant to the correct network in your compose file.

3. Check Traefik's TOML Config for Conflicts

  • exposedByDefault setting: If your Traefik config has [providers.docker] exposedByDefault = false, any container without traefik.enable=true will be ignored. This is likely why Portainer works (you added the label) but HomeAssistant doesn't.
  • Route conflicts: Make sure no other Traefik router has a rule that overlaps with HomeAssistant's domain (e.g., a wildcard rule like Host(*.yourdomain.com) that's prioritized higher). Check the order of your routers—Traefik uses the most specific rule first, but if a wildcard catches the request before your HomeAssistant rule, it might route to the wrong service.

4. Dig Into the Logs

Compare the successful Portainer logs with the failed HomeAssistant logs to spot differences:

  • In Traefik's logs, look for lines like no route found for GET / when accessing HomeAssistant—this confirms Traefik doesn't recognize the request as matching any router rule.
  • Check HomeAssistant's container logs with docker logs homeassistant to ensure the service is actually running and listening on port 8123. If HomeAssistant isn't started, even direct access would fail, which would explain the 404.

5. Test Direct Access to HomeAssistant

Bypass Traefik entirely to rule out container-level issues:

  • Access http://your-server-ip:8123 directly. If this works, the problem is definitely in Traefik's routing configuration. If it doesn't, fix HomeAssistant's container setup first (e.g., ensure the port is mapped correctly, or the service is starting properly).

Once you check these areas, you should be able to pinpoint the exact cause of the 404. If you share your actual configs/logs, I can help narrow it down further!

内容的提问来源于stack exchange,提问作者uav2608

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 03:48:35