【发布时间】: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