【问题标题】:Attempt to rewrite minimal Traefik example to use TLS does not work尝试重写最小 Traefik 示例以使用 TLS 不起作用
【发布时间】:2022-11-10 09:04:30
【问题描述】:

https://doc.traefik.io/traefik/user-guides/docker-compose/basic-example/ 的最小示例适用于我的本地计算机。但是,当我尝试调整它以使用 TLS 时,我遇到了一个问题。我是 Traefik 新手,所以我可能会犯一个愚蠢的错误。

这是我的尝试:

version: "3.3"

services:

  traefik:
    image: "traefik:v2.8"
    container_name: "traefik"
    command:
      - "--log.level=DEBUG"
      - "--accesslog=true"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
    ports:
      - "443:443"
      - "8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"

  whoami:
    image: "traefik/whoami"
    container_name: "simple-service"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.whoami.rule=Host(`127.0.0.1`)"
      - "traefik.http.routers.whoami.entrypoints=websecure"

所以主要的修改是使用"traefik.http.routers.whoami.entrypoints=websecure"而不是"traefik.http.routers.whoami.entrypoints=web"

跑步

$ curl -k https://127.0.0.1

我明白了

404 page not found

traefik 日志显示没有与路由相关的问题,并且使用curl https://127.0.0.1:8080/api/rawdata | jq . 显示的路由等的内部 traefik 设置看起来与工作示例之一相同,除了更改的端口。

【问题讨论】:

    标签: docker-compose reverse-proxy traefik


    【解决方案1】:

    将以下条目添加到您的 Traefik: "--entrypoints.websecure.address=:8080"

    通常,http 为 8080,https 替代端口为 8443,但由于您的示例特别说明了 https://~:8080,因此我已相应地对其进行了调整。

    【讨论】:

    • 不起作用,端口8080 已被使用,因为这是--api.insecure=true 启用的服务端口。我使用 `https://~:8080` 的示例正在运行,它转储了可用于调试的 traefik 的内部设置。
    【解决方案2】:

    所以我选择了新的答案,而不是仅仅编辑旧的答案。 (即使是不正确的答案也会教一些东西)。

    我的参考是 Marc Mogdanz 的这篇很棒的帖子(链接:https://marcmogdanz.de/posts/infrastructure-with-traefik-and-cloudflare/)。

    您的查询的直接答案是:

    1. 公开 8080 端口但不发布
    2. 添加主机名规则。这将允许 Traefik 将 URL 请求路由到它自己的端口 8080。

      撰写文件的受影响部分如下(假设 URL https://dashboard.example.com 是到达仪表板的所需 URL):

      expose:
        - 8080
      ...
      labels: 
        - "traefik.enable=true"
        - "traefik.http.routers.traefik.rule=Host(`dashboard.example.com`)"
        - "traefik.http.routers.traefik.tls=true"
        - "traefik.http.services.traefik.loadbalancer.server.port=8080"
      

      最后,我注意到您正在本地主机上进行测试。如果您在本地机器上进行测试,请使用localhost 作为仪表板,并使用127.0.0.1 作为 whoami。

      或者,或者,为子域添加静态条目(请参阅https://stackoverflow.com/a/19016600)。

      无论哪种方式,Traefik 在匹配主机规则时都会查看请求的 SNI - 不一定是 IP 地址。

      
      Request ----> Docker:443 ---> {Traefik}-"SNI?"---"127.0.0.1"---> {whoami}
                                       |         
                                       |          
                                     8080<---"dashboard.localhost"
      
      

    【讨论】:

      猜你喜欢
      • 2020-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-16
      • 2018-11-03
      • 1970-01-01
      相关资源
      最近更新 更多