【问题标题】:Traefik rewrite pathTraefik 重写路径
【发布时间】:2021-05-20 12:46:45
【问题描述】:

我在my.host.com/foo/bar/docpath 有一个文档,我希望它可以在网址my.host.com/docpath 上找到。我所有的 Traefik 配置都在一个 docker-compose 文件中。

这是我的服务容器中的配置:

labels:
      traefik.enable: "true"
      traefik.http.routers.myservice.entrypoints: secure
      traefik.http.routers.myservice.middlewares: rewritepath
      traefik.http.routers.myservice.rule: "Host(`my.host.com`) && Path(`/docpath`)"

在 Traefik 的容器标签中:

labels:
      traefik.http.middlewares.rewritepath.addprefix.prefix: /foo/bar

问题:当我请求 my.host.com/docpath 时,出现 404 错误。我做错了什么?

(假设我使用简单的规则正确访问my.host.com/foo/bar/docpath:“Host(`my.host.com`)”并且没有中间件)

【问题讨论】:

    标签: traefik


    【解决方案1】:

    我对 traefik 的理解是,中间件是在规则之后调用的。

    试试这个。

      - "traefik.http.routers.myservice.rule: "Host(`my.host.com`) && Path(`/docpath`)"
      - "traefik.http.routers.myservice.middlewares=rewritepath"
      - "traefik.http.middlewares.rewritepath.addprefix.prefix=/foo/bar"
    

    【讨论】:

    • 就是这样,中间件定义只需要在同一个容器配置中。非常感谢!
    • 这在 Traefik 的文档中确实不是很清楚,什么时候应该在 Traefik 的服务或其他服务的定义中放置标签。我也很挣扎。我实际上写了一篇关于如何设置几个 Traefik 选项的教程,也许它会对您遇到的其他问题有所帮助:juliensalinas.com/en/…
    猜你喜欢
    • 2018-11-03
    • 1970-01-01
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多