doudeng1870 2018-07-31 08:02
浏览 532

如何在Traefik中编写PathPrefixStripRegex?

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?