我正在盡我最大的努力通過http://gateway.localhost/dashboard/獲得 Traefik 儀表板,但我總是從 Traefik 收到 404 回應*。請查看我的堆疊檔案并告訴我,為什么它不起作用?
我在具有有效域的服務器上嘗試了它,但它要么在那里作業,要么在 Swarm 模式下使用 Docker 桌面在本地主機上作業。可以通過正確的 http://localhost 訪問 WhoAmI 服務。
docker stack deploy -c traefik.yml traefik
*404 也為這些路由回傳:http://gateway.localhost , http://gateway.localhost/dashboard
traefik.yml:
version: '3'
services:
reverse-proxy:
image: traefik:v2.5
command:
- "--providers.docker.swarmmode=true"
- "--providers.docker.exposedByDefault=false"
- "--api.dashboard=true"
- "--entrypoints.web.address=:80"
# Logging
- "--accesslog"
- "--log.level=INFO"
ports:
- "80:80"
deploy:
labels:
#Because Swarm API does not support automatic way
- "traefik.http.services.reverse-proxy.loadbalancer.server.port=80"
#Dashboard
- "traefik.http.routers.dashboard.rule=Host(`gateway.localhost`) && (PathPrefix(`/api`) || PathPrefix(`/dashboard`))"
- "traefik.http.routers.dashboard.service=api@internal"
- "traefik.http.routers.dashboard.entrypoints=web"
- "traefik.http.routers.dashboard.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
placement:
constraints:
- node.role == manager
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
whoami:
image: traefik/whoami
deploy:
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.rule=Host(`localhost`)"
- "traefik.http.routers.whoami.entrypoints=web"
- "traefik.http.services.whoami.loadbalancer.server.port=80"
uj5u.com熱心網友回復:
您需要為帶有traefik.enable=true標簽的容器啟用 traefik :
version: '3'
services:
reverse-proxy:
image: traefik:v2.5
command:
- "--providers.docker.swarmmode=true"
- "--providers.docker.exposedByDefault=false"
- "--api.dashboard=true"
- "--entrypoints.web.address=:80"
# Logging
- "--accesslog"
- "--log.level=INFO"
ports:
- "80:80"
deploy:
labels:
######## add the following label to enable traefik #######
- "traefik.enable=true"
#Because Swarm API does not support automatic way
- "traefik.http.services.reverse-proxy.loadbalancer.server.port=80"
#Dashboard
- "traefik.http.routers.dashboard.rule=Host(`gateway.localhost`) && (PathPrefix(`/api`) || PathPrefix(`/dashboard`))"
- "traefik.http.routers.dashboard.service=api@internal"
- "traefik.http.routers.dashboard.entrypoints=web"
- "traefik.http.routers.dashboard.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
placement:
constraints:
- node.role == manager
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
whoami:
image: traefik/whoami
deploy:
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.rule=Host(`localhost`)"
- "traefik.http.routers.whoami.entrypoints=web"
- "traefik.http.services.whoami.loadbalancer.server.port=80"
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/368176.html
