[英]Traefik dasboard not working with subdomain
I am trying to setup Traefik dashboard under a subdomain, but I am getting 404 page not found.我正在尝试在子域下设置 Traefik 仪表板,但我收到 404 页面未找到。 However, I can access the api without any problems.
但是,我可以毫无问题地访问 api。 Below is the docker-compose.yml that I have created.
下面是我创建的 docker-compose.yml。
version: '3.7'
services:
traefik:
image: traefik:v2.9.6
container_name: traefik
hostname: traefik
restart: always
ports:
- 80:80
- 8080:8080
command:
- --api.insecure=true
- --api.dashboard=true
- --api.debug=true
- --log.level=DEBUG
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --providers.docker.network=traefikweb
- --entrypoints.web.address=:80
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- traefikweb
labels:
- traefik.enable=true
- traefik.http.routers.dashboard.rule=Host(`traefik.example.com`) && PathPrefix(`/dashboard`)
- traefik.http.routers.dashboard.service=dashboard@internal
- traefik.http.routers.dashboard.entrypoints=web
- traefik.http.routers.api.rule=Host(`traefik.example.com`) && PathPrefix(`/api`)
- traefik.http.routers.api.service=api@internal
- traefik.http.routers.api.entrypoints=web
networks:
traefikweb:
external: true
I need guidance what I am doing wrong and why traefik.example.com/api/rawdata works and traefik.example.com/dashboard won't.我需要指导我做错了什么以及为什么 traefik.example.com/api/rawdata 有效而 traefik.example.com/dashboard 无效。 Thanks
谢谢
My solution based on larsks answer:我基于 larsks 答案的解决方案:
version: '3.7'
services:
traefik:
image: traefik:v2.9.6
container_name: traefik
hostname: traefik
restart: always
ports:
- 80:80
command:
- --api.insecure=true
- --api.dashboard=true
- --api.debug=true
- --log.level=DEBUG
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --providers.docker.network=traefikweb
- --entryPoints.web.address=:80
- --accessLog.filePath=/dev/stderr
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- traefikweb
labels:
- traefik.enable=true
- traefik.http.routers.dashboard.rule=Host(`traefik.example.com`)
- traefik.http.routers.dashboard.service=dashboard@internal
- traefik.http.routers.dashboard.entrypoints=web
- traefik.http.routers.api.rule=Host(`traefik.example.com`) && PathPrefix(`/api`)
- traefik.http.routers.api.service=api@internal
- traefik.http.routers.api.entrypoints=web
networks:
traefikweb:
external: true
Usage:用法:
http://traefik.example.com -> will take you to dashboard http://traefik.example.com -> 将带您到仪表板
http://traefik.example.com/api/rawdata -> will take you to api http://traefik.example.com/api/rawdata -> 将带你到 api
I have also removed port forwarding 8080:8080.我还删除了端口转发 8080:8080。 So only way to access the api is through the url http://traefik.example.com/api/.. .
所以访问 api 的唯一方法是通过 url http://traefik.example.com/api/.. 。
This is my first step towards dashboard and api routing.这是我迈向仪表板和 api 路由的第一步。 Next step is to secure it.
下一步是保护它。
I've been poking at this for a bit and the following configuration works for me.我一直在研究这个,下面的配置对我有用。 This exposes the dashboard at
http://traefik.internal/dashboard
and the API at http://traefik.internal/api
.这会在 http://traefik.internal/dashboard 公开仪表板,在
http://traefik.internal/dashboard
http://traefik.internal/api
API。
version: '3.7'
services:
traefik:
image: traefik:v2.9.6
container_name: traefik
hostname: traefik
restart: always
ports:
- 80:80
- 8080:8080
command:
- --api.insecure=true
- --api.dashboard=true
- --api.debug=true
- --log.level=INFO
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --providers.docker.network=traefikweb
- --entrypoints.web.address=:80
- --accessLog.filePath=/dev/stderr
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- traefikweb
labels:
- traefik.enable=true
- traefik.http.routers.api.rule=Host(`traefik.internal`) && PathPrefix(`/api`)
- traefik.http.routers.api.service=api@internal
- traefik.http.routers.api.entrypoints=web
- traefik.http.routers.dashboard.rule=Host(`traefik.internal`) && PathPrefix(`/dashboard`)
- traefik.http.routers.dashboard.service=dashboard@internal
- traefik.http.routers.dashboard.entrypoints=web
# configure stripprefix rule for the dashboard
- traefik.http.routers.dashboard.middlewares=dashboard-stripprefix
- traefik.http.middlewares.dashboard-stripprefix.stripprefix.prefixes=/dashboard
networks:
traefikweb:
external: true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.