gpt4 book ai didi

docker - Traefik 仪表板是空的

转载 作者:行者123 更新时间:2023-12-05 05:39:40 24 4
gpt4 key购买 nike

我已经在我的产品(django、postgresql、gunicorn)中实现了 traefik,当我使用我的/api 和/admin 时,所有的工作都是正确的。

但 traefik 的仪表板工作不正确(我可以登录并转到/dashboard/,但它显示空白字段。)

enter image description here

日志:

web                   | Not Found: /api/overview
me-project-traefik-1 | 78.24.102.87 - - [15/Jun/2022:10:21:42 +0000] "GET /api/overview HTTP/2.0" 404 179 "-" "-" 104 "web@docker" "http://172.21.0.4:8000" 6ms
web | Not Found: /api/overview
me-project-traefik-1 | 78.24.102.87 - - [15/Jun/2022:10:21:47 +0000] "GET /api/overview HTTP/2.0" 404 179 "-" "-" 105 "web@docker" "http://172.21.0.4:8000" 2ms
web | Not Found: /api/overview
me-project-traefik-1 | 78.24.102.87 - - [15/Jun/2022:10:21:52 +0000] "GET /api/overview HTTP/2.0" 404 179 "-" "-" 106 "web@docker" "http://172.21.0.4:8000" 2ms
web | Not Found: /api/overview
me-project-traefik-1 | 78.24.102.87 - - [15/Jun/2022:10:21:57 +0000] "GET /api/overview HTTP/2.0" 404 179 "-" "-" 107 "web@docker" "http://172.21.0.4:8000" 2ms
web | Not Found: /api/overview
me-project-traefik-1 | 78.24.102.87 - - [15/Jun/2022:10:22:02 +0000] "GET /api/overview HTTP/2.0" 404 179 "-" "-" 108 "web@docker" "http://172.21.0.4:8000" 2ms
web | Not Found: /api/overview
me-project-traefik-1 | 78.24.102.87 - - [15/Jun/2022:10:22:07 +0000] "GET /api/overview HTTP/2.0" 404 179 "-" "-" 109 "web@docker" "http://172.21.0.4:8000" 3ms

docker-compose 文件:

version: '3.7'
services:
web:
container_name: web
build:
context: ./MoreEnergy
dockerfile: Dockerfile.prod
restart: always
env_file: ./.env.prod
entrypoint: sh ./entrypoint.sh
command: gunicorn MoreEnergy.wsgi:application --bind 0.0.0.0:8000
expose:
- 8000
volumes:
- static_volume:/home/app/web/staticfiles
- media_volume:/home/app/web/mediafiles
depends_on:
- db
labels:
- "traefik.enable=true"
- "traefik.http.routers.web.rule=Host(`my.site.com`)"
- "traefik.http.routers.web.tls=true"
- "traefik.http.routers.web.tls.certresolver=letsencrypt"
db:
container_name: dev_db
image: postgres:12.0-alpine
ports:
- "5432:5432"
env_file: ./.env.prod
volumes:
- postgres_data:/var/lib/postgresql/data/
traefik:
build:
context: ./traefik
dockerfile: Dockerfile.traefik
ports:
- 80:80
- 443:443
- 8080:8080
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./traefik-public-certificates:/certificates"
command:
- "--api=true"
- "--api.dashboard=true"
- "--providers.docker=true"
labels:
- "traefik.enable=true"
- "traefik.http.routers.api.entrypoints=dashboard"
- "traefik.http.routers.dashboard.rule=Host(`my.site.com`) && PathPrefix(`/dashboard`)"
- "traefik.http.routers.dashboard.tls=true"
- "traefik.http.routers.dashboard.tls.certresolver=letsencrypt"
- "traefik.http.routers.dashboard.service=api@internal"
- "traefik.http.routers.dashboard.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/"


volumes:
postgres_data:
static_volume:
media_volume:

可能,traefik 试图发出他的内部 api 请求,但无法访问它们。我的项目中有带有“/api/”前缀的 api。我想,traefik 与我的 api 有冲突。还是不行?

真实主机名被替换为 my.site.com

最佳答案

I guess, traefik has conflict with my api. Or not?

是的,有冲突。

在您的示例中,仪表板规则设置为

- "traefik.http.routers.dashboard.rule=Host(`my.site.com`) && PathPrefix(`/dashboard`)"

但是,根据 Dashboard Router Rule 上的文档,您需要确保:

As underlined in the documentation for the api.dashboard option, the router rule defined for Traefik must match the path prefixes /api and /dashboard.

这是与您的应用程序的冲突。查看Traefik's API Endpoints的综合列表您可以通过提供以下仪表板规则来解决此问题:

- "traefik.http.routers.dashboard.rule="Host(`my-domain.com`) && (PathPrefix(`/debug`) ||PathPrefix(`/api/http`) || PathPrefix(`/api/tcp`) || PathPrefix(`/api/udp`) || PathPrefix(`/api/entrypoints`) || PathPrefix(`/api/overview`) || PathPrefix(`/api/rawdata`) || PathPrefix(`/api/version`) || PathPrefix(`/dashboard`))"

只需确保它捕获所有相关端点并且不会干扰您的自定义应用程序。

关于docker - Traefik 仪表板是空的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72629847/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com