首页 > 解决方案 > How to write PathPrefixStripRegex in Traefik?

问题描述

I have a Docker containers that are running on the ECS Cluster on AWS. I am using Traefik to route certain routes to services. For this I am using DockerLabels option in CloudFormation and one of them is traefik.frontend.rule and PathPrefixStripRegex. I had before PathPrefixStrip rule as

traefik.frontend.rule: "PathPrefixStrip: /api/service-name"

and everything was working without a problem. Now I am trying to expand the api part to match multiple values like

traefik.frontend.rule: "PathPrefixStripRegex: /{basepath:(?:api|docs)}/service-name"

The problem is what ever url I call the whole path is stripped. So for example, if I call

https://my.example.org/api/service-name/health

the Traefik is stripping everything. So /api/service-name/health part is removed and the service is being called at the / (root) path.

Does anyone have any clue why the whole path is being stripped? Is the regex part wrong, I know the Traefik is using Gorilla mux under the hood and frankly I do not have any experience with Go nor mux.

I have tried to use /(api|docs)/service-name as regex. On regex101 site, it works as expected, when I tried to use it as a rule in Traefik, it does not. The version of Traefik is 1.7.

标签: regexgostriptraefikmux

解决方案


推荐阅读