Docker 在Traefik 2.0中设置basic auth以与R plumber API一起使用
我正在尝试扩展我的R PlumberAPI,并开始使用Traefik 2.0作为一种公开、负载平衡和保护用R编写的rest API的方法。我无法让Traefik添加基本身份验证并将路径和查询参数传递给运行我的API的容器。基本身份验证工作正常,我可以正确设置容器的反向代理,但不能同时设置两者。下面的设置导致404错误 我能很好地运行集装箱水管工API。 我可以通过traefik(见下图)通过路径“API_test”使用支架技术/管道工docker图像访问集装箱管道工API。 我可以使用Traefik的whoami示例(如下所示)设置basic auth,它可以正常工作(ig) 我无法成功添加下面注释掉的两行。我希望这两行代码添加基本的auth,当它工作时,我会得到一个404错误,而不是获取预期的信息Docker 在Traefik 2.0中设置basic auth以与R plumber API一起使用,docker,traefik,plumber,Docker,Traefik,Plumber,我正在尝试扩展我的R PlumberAPI,并开始使用Traefik 2.0作为一种公开、负载平衡和保护用R编写的rest API的方法。我无法让Traefik添加基本身份验证并将路径和查询参数传递给运行我的API的容器。基本身份验证工作正常,我可以正确设置容器的反向代理,但不能同时设置两者。下面的设置导致404错误 我能很好地运行集装箱水管工API。 我可以通过traefik(见下图)通过路径“API_test”使用支架技术/管道工docker图像访问集装箱管道工API。 我可以使用Traef
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/"
通过发布的设置,我可以使用端点“”,响应是一些随机选择的数字的平均值
当我添加两个auth行(当前已注释掉)时,当我需要一个数字时,会出现404错误。此处
- "traefik.http.routers.api_test.middlewares=api_test-replacepathregex@docker"
删除@docker
,这样它就应该
- "traefik.http.routers.api_test.middlewares=api_test-replacepathregex"
这里
删除@docker
,这样它就应该
- "traefik.http.routers.api_test.middlewares=api_test-replacepathregex"