我正在尝试扩大我的R plumber API的规模,并开始使用Traefik 2.0作为公开,负载均衡和保护其余用R编写的API的方式。我无法让traefik添加基本的身份验证 and 将路径和查询参数传递给运行我的API的容器。基本身份验证有效,我可以正确设置容器的反向代理,但不能同时设置反向代理。下面的设置会导致404错误。
我可以很好地运行容器化的管道工API。 我可以使用trestletech / plumber docker映像通过路径“ api_test”通过traefik(如下所示)访问容器化的管道工API。 我可以使用Traefik的whoami示例(如下所示)设置基本身份验证,并且它可以正常工作(例如,ig http://localhost/traefexample/whoami)。
我不能成功添加下面注释掉的两行。我希望这两行添加基本身份验证,并且在此行得通的同时,我收到404错误,而不是得到了预期的信息。
version: '3.7'
services:
reverse-proxy:
# The official v2.0 Traefik docker image
image: traefik:v2.0
# Enables the web UI and tells Traefik to listen to docker
command:
- --entrypoints.web.address=:80
- --entrypoints.websecure.address=:443
- --api.insecure=true
- --providers.docker
ports:
# The HTTP port
- "80:80"
- "8000:8080"
volumes:
# So that Traefik can listen to the Docker events
- /var/run/docker.sock:/var/run/docker.sock
api_test:
# An R plumber api in a docker container
image: trestletech/plumber
labels:
- "traefik.http.routers.api_test.rule=Path(`/api_test/{path:.+}`)"
- "traefik.http.middlewares.api_test-replacepathregex.replacepathregex.regex=/api_test(.*)"
- "traefik.http.middlewares.api_test-replacepathregex.replacepathregex.replacement=$$1"
- "traefik.http.routers.api_test.middlewares=api_test-replacepathregex@docker"
# - "traefik.http.routers.api_test.middlewares=auth"
# - "traefik.http.middlewares.auth.basicauth.users=user:$$apr1$$q8eZFHjF$$Fvmkk//V6Btlaf2i/ju5n/"
traefexample:
# A container that exposes an API to show its IP address - example from traefik basic, auth is working
image: containous/whoami
labels:
- "traefik.http.routers.traefexample.rule=Path(`/traefexample/{path:.+}`)"
- "traefik.http.middlewares.traefexample-replacepathregex.replacepathregex.regex=/traefexample(.*)"
- "traefik.http.middlewares.traefexample-replacepathregex.replacepathregex.replacement=$$1"
- "traefik.http.routers.traefexample.middlewares=traefexample-replacepathregex@docker"
- "traefik.http.routers.traefexample.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.users=user:$$apr1$$q8eZFHjF$$Fvmkk//V6Btlaf2i/ju5n/"
使用发布的设置,我可以使用端点“ http://localhost/api_test/mean”,并且响应是一些随机选择的数字的平均值。
当我添加两条身份验证行(当前已注释掉)时,当我期望一个数字时出现404错误。
答案 0 :(得分:0)
这里
- "traefik.http.routers.api_test.middlewares=api_test-replacepathregex@docker"
删除@docker
,因此应该为
- "traefik.http.routers.api_test.middlewares=api_test-replacepathregex"