Reputation: 85
I would like to route all subdomains of a domain to one backend service and append the respective subdomain in the backend URL.
For example, http://mysubdomain.example.com/api/hello-world becomes http://backend-service/api/mysubdomain/hello-world.
So the following scheme: http://backend-service/api/[subdomain]/[remaining-url]
Current configuration in docker.compose.yml (not working, regex does not match and replace):
- "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"
It seems like the regex doesn't match. What could be the reason or how could I solve my problem?
Upvotes: 3
Views: 1133
Reputation: 41
Try this:
- "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"
Upvotes: -1