【问题标题】:How to pass Traefik subdomain to backend URL如何将 Traefik 子域传递给后端 URL
【发布时间】:2022-12-21 06:58:00
【问题描述】:

我想将一个域的所有子域路由到一个后端服务,并在后端 URL 中附加相应的子域。

例如,http://mysubdomain.example.com/api/hello-world 变为 http://backend-service/api/mysubdomain/hello-world。

所以下面的方案:http://backend-service/api/[subdomain]/[remaining-url]

docker.compose.yml 中的当前配置(不工作,正则表达式不匹配和替换):

- "traefik.http.routers.registry.rule=HostRegexp(`{subdomain:[a-zA-Z0-9]+}.exmaple.com`) && PathPrefix(`/api`)" 

- traefik.http.middlewares.registrypath.replacepathregex.regex=^http://(.*).example.com/api/(.*)$$
- traefik.http.middlewares.registrypath.replacepathregex.replacement=/api/$$1/$$2
- "traefik.http.routers.registry.middlewares=registrypath@docker"

似乎正则表达式不匹配。可能是什么原因或我该如何解决我的问题?

【问题讨论】:

    标签: regex docker docker-compose regex-group traefik


    【解决方案1】:

    试试这个:

    - "traefik.http.routers.registry.rule=HostRegexp(`{subdomain:[a-zA-Z0-9]+}.exmaple.com`) && PathPrefix(`/api`)" 
    - "traefik.http.middlewares.registrypath.replacepathregex.regex=^http://(.*).example.com/api/(.*)"
    - "traefik.http.middlewares.registrypath.replacepathregex.replacement=http://example.com/api/$${1}/$${2}"
    - "traefik.http.routers.registry.middlewares=registrypath@docker"
    

    【讨论】:

      猜你喜欢
      • 2019-04-19
      • 1970-01-01
      • 2020-08-17
      • 2015-02-03
      • 1970-01-01
      • 1970-01-01
      • 2015-08-31
      • 2011-10-18
      • 1970-01-01
      相关资源
      最近更新 更多