Docker ForwardAuth中间件在Traefik中不能作为API网关工作
我试图将Traefik作为API网关运行,并希望通过使用以下docker compose文件触发ForwardAuth中间件,但未命中auth端点的中间件。我将它与localhost一起使用Docker ForwardAuth中间件在Traefik中不能作为API网关工作,docker,traefik,api-gateway,Docker,Traefik,Api Gateway,我试图将Traefik作为API网关运行,并希望通过使用以下docker compose文件触发ForwardAuth中间件,但未命中auth端点的中间件。我将它与localhost一起使用 version: '3' services: reverse-proxy: image: traefik # The official Traefik docker image command: --api --docker # Enables the web UI and tells
version: '3'
services:
reverse-proxy:
image: traefik # The official Traefik docker image
command: --api --docker # Enables the web UI and tells Traefik to listen to docker
ports:
- "80:80" # The HTTP port
- "8080:8080" # The Web UI (enabled by --api)
volumes:
- /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
- $PWD/traefik.toml:/traefik.toml
whoami:
image: emilevauge/whoami
labels:
- traefik.enable=true
- "traefik.frontend.rule=Host:whoami.docker.localhost"
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.scheme=https"
- "traefik.http.middlewares.test-replacepath.replacepath.path=/foo"
- "traefik.http.middlewares.testauth.ForwardAuth.Address=http://localhost:55391/api/Auth"
我也为此挣扎了一段时间,除了在Traefik文档中找到答案外,在其他任何地方都找不到答案。实际上,我并没有提到这一点,但我突然注意到,您不仅需要指定中间件,还必须将其应用于路由器 将此标签添加到whoami服务应该可以做到以下几点:
- "traefik.http.routers.whoami.middlewares=testauth"
请注意,您也可以在此处通过逗号分隔指定多个中间件,以便添加您定义的其他中间件,如下所示:
- "traefik.http.routers.whoami.middlewares=testauth,test-redirectscheme,test-replacepath"