【问题标题】:Treafik Path RoutingTraefik 路径路由
【发布时间】:2018-11-13 12:05:43
【问题描述】:

我想访问 api.example.com/example 下的 docker-compose 服务。因此我有以下 docker-compose.yml

  example:
    image: example    
    labels:
            - "traefik.frontend.rule=Host:api.example.com;PathPrefixStrip:/example/"
            - "traefik.enable=true"
            - "traefik.protocol=http"
            - "traefik.frontend.entryPoints=https"

我可以访问此路径下的服务。但是页面中的所有链接都指向错误的 URL,例如 api.example.com/link 而不是 api.example.com/example/link

由于此路径问题,css 也无法正确加载。 什么是让它工作的正确路径配置?

从文档中阅读,X-Forwarded-Prefix 应该是解决方案,但没有文档。

【问题讨论】:

    标签: docker docker-compose reverse-proxy traefik


    【解决方案1】:

    如果我理解正确,您只想将匹配 api.example.com/example/* 的请求路由到此 example 服务。那么你应该使用PathPrefix:/example/

    你所期望的:PathPrefixStrip,顾名思义,尝试匹配路径,然后,在将流量路由到服务之前将其删除。

    【讨论】:

    • 是的,但我背后的服务正在收听/ 而不是/example/,所以我必须剥离example,所以这不起作用,不是吗?
    • 据我所知,服务器不会监听路径,它们总是“监听”/(它们在主机上)。不过,您的 api 可以在您喜欢的任何路径上,将 / 留给 404 页面。
    • 是的,这是正确的,但我因此使用 traefik。我想让几台服务器监听/,但路径由 traefik 路由。我认为 PathPrefixStrip 正是因此。相反,我不明白 traefik 与路径的使用
    • 这里的目标是有一个更精细的扩展控制,解耦系统(微服务的概念),同时在外部世界表现为一台服务器。
    • 当你说你想让几个服务器监听/时,你的意思是服务器A和服务器都响应域/测试?
    【解决方案2】:

    您是否尝试添加规则?

    - "traefik.frontend.rule=Host:api.example.com;PathPrefixStrip:/example/; AddPrefix: /example" 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-22
      • 2021-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多