gpt4 book ai didi

docker - traefik 2.2 反向代理 https 不显示我的容器

转载 作者:行者123 更新时间:2023-12-02 18:07:07 27 4
gpt4 key购买 nike

我正在 docker 中使用 traefik v2.2 设置测试环境。我设置了一个名为 traefik 的 docker 网络,带有一个测试 web 容器。如果我导航到 https://test.com,我可以看到我的仪表板,但是我看不到我的当我导航到规则设置的路径时的容器(即 https://test.com/myapp )

在仪表板中,状态看起来一切正常,显示了 myapp 容器的内部 ip,路由器和 https 入口点都正常。

如果我去https://test.com/myapp它给出了一个自定义的 404 页面“错误代码解释:404 = 没有匹配给定的 URI。”如果我去https://test.com/somenonexistantpath它给了我一个常规的 404 not found 消息

我试过更改主机规则。我将 traefik.docker.network=traefik 添加到容器标签,以防它们与 traefik 容器不在同一网络上,并验证我可以到达 http://myapp:80从 traefik 容器内部。根据 traefik v2 文档,主机规则看起来是正确的,所以我想知道我是否遗漏了什么。

我确实测试了将 test.com 主机规则移动到 myapp 并且能够到达测试站点,所以我好像缺少一些路径

下面是我的 docker-compose 文件,配置文件 dynamic-traefik.yaml 只有 tls 信息

version: '3.3'

networks:
traefik:
external: true



services:
traefik:
image: traefik:v2.2 #latest pull as of Feb 25, 2020
container_name: traefik
restart: always
networks:
- traefik
ports:
- "443:443"
volumes:
- ${PWD}/traefik:/traefik # Traefik static config
- /var/run/docker.sock:/var/run/docker.sock:ro # SSL Development certificates
command:
- "--log.level=DEBUG"
#- "--accesslog=true"
- "--api=true"
- "--api.dashboard=true"
- "--api.debug=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--providers.docker.network=traefik"
- "--providers.docker.endpoint=unix:///var/run/docker.sock"
- "--providers.docker.watch=true"
- "--entrypoints.https.address=:443"
# apparently you still neeed an extra file to specify TLS
- "--providers.file.filename=/traefik/dynamic-traefik.yaml"
labels:
- "traefik.enable=true"
# Traefik Dashboard
- "traefik.http.routers.traefik.rule=Host(`test.com`)" #works but only gives you dashboard
- "traefik.http.routers.traefik.service=api@internal"
- "traefik.http.routers.traefik.entrypoints=https"
- "traefik.http.routers.traefik.tls=true"
- "traefik.docker.network=traefik"




myapp:
image: yeasy/simple-web:latest
container_name: myapp
restart: always
networks:
- traefik
labels:
- "traefik.enable=true"
- "traefik.http.routers.myapp.entrypoints=https"
- "traefik.http.routers.myapp.rule=Host(`test.com`) && PathPrefix(`/myapp`)"
- "traefik.http.routers.myapp.service=myapp"
- "traefik.http.routers.myapp.tls=true"
- "traefik.http.services.myapp.loadbalancer.server.port=80" #this is needed to point to the correct port on the service container
- "treafik.docker.network=traefik"

最佳答案

你需要指定priority并为 myapp 路由器提高它,以便它首先处理

关于docker - traefik 2.2 反向代理 https 不显示我的容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60606789/

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