最后,在配置上花费了大量时间之后,我却束手无策了。本来应该很简单的事情却变得相当复杂。希望有人能帮我找到解决方案。
我正在尝试使用 Traefik 运行容器。我没有像许多人一样将所有配置放在容器的 docker-compose 文件 (docker-compose.yml) 中,而是将配置放在专用文件 (traefik.yml) 中,因为这对我来说更灵活。
我有以下用于 Traefik 的 docker-compose.yml 文件:
version: "3.8"
services:
traefik:
image: traefik:latest
hostname: traefik
container_name: traefik
restart: unless-stopped
command:
- "--configFile=/traefik.yml"
networks:
- traefik_gw_bridge
ports:
- 80:80
- 443:443
- 8080:8080
volumes:
- ./traefik.yml:/traefik.yml
- logs:/logs
- letsencrypt:/letsencrypt
- /var/run/docker.sock:/var/run/docker.sock:ro
healthcheck:
test: ["CMD", "traefik", "healthcheck", "--ping"]
interval: 10s
timeout: 6s
retries: 2
start_period: 5s
networks:
traefik_gw_bridge:
driver: bridge
external: true
volumes:
letsencrypt:
logs:
这些是我用于 traefik.yml 的配置参数:
api:
dashboard: true
insecure: false
ping:
entryPoint: web
providers:
docker:
endpoint: "unix:///var/run/docker.sock"
exposedByDefault: false
entryPoints:
web:
address: ":80"
websecure:
address: ":443"
traefik:
address: ":8080"
http:
routers:
dashboard:
rule: "Host(`traefikdash.mydomain.com`)"
entryPoints:
- traefik
service: api@internal
middlewares:
- auth
middlewares:
auth:
basicAuth:
users:
- "admin:$apr1$Nzj4xQwY$QiXQ/eYHzKTFS.Lx.6XG71"
log:
filePath: "/logs/traefik.log"
format: json
level: DEBUG
accessLog:
filePath: "/logs/access.log"
bufferingSize: 150
certificatesResolvers:
le:
acme:
email: "[email protected]"
storage: "/letsencrypt/acme.json"
httpChallenge:
entryPoint: "web"
从逻辑上讲,在配置文件的以下部分,我尝试定义一个路由器,以使用用户名和密码为仪表板设置基本身份验证:
http:
routers:
dashboard:
rule: "Host(`traefikdash.mydomain.com`)" # Reemplaza `yourdomain.com` con tu dominio
entryPoints:
- traefik
service: api@internal
middlewares:
- auth
middlewares:
auth:
basicAuth:
users:
- "admin:$apr1$Nzj4xQwY$QiXQ/eYHzKTFS.Lx.6XG71"
我无法得到我想要的结果。当我访问traefikdash.mydomain.com
或traefikdash.mydomain.com:8080
或traefikdash.mydomain.com:8080/dashboard
/ 时traefikdash.mydomain.com/dashboard
,我只是从 Traefik 和我的浏览器得到以下响应:
- HTTP 404 页面未找到
- 错误连接被拒绝
尝试了各种类型的配置后,我根本找不到有关如何实现 HTTP 基本身份验证以访问 Traefik 仪表板的更多信息。