设置:带有一个Traefik容器,Apache容器,多个其他容器(例如,在子路径后面运行的portainer)的Docker(18.09.6)
Apache已配置
- traefik.frontend.rule=Host:${hostname},www.${hostname}
portainer配置为
- traefik.frontend.redirect.regex=^(.*)/portainer$$
- traefik.frontend.redirect.replacement=$$1/portainer/
- "traefik.frontend.rule=PathPrefix:/portainer;ReplacePathRegex: ^/portainer/(.*) /$$1"
Apache容器正在提供URL https://hostname,例如https://hostname/test
通过https://hostname/portainer
现在我想扩展Apache容器的子域,例如
- traefik.frontend.rule=Host:${hostname},autoconfig.${hostname},autodiscover.${hostname},mta-sts.${hostname},www.${hostname}
现在发生以下情况:
https://hostname有用
https://hostname/test有用
https://autodiscover.hostname有效
https://hostname/portainer停止工作
根据日志,Traefik将流量路由到Apache容器而不是Portainer容器
这是可复制的,并且与多个前端条目有关。我找不到包含超过2个前端规则的示例 也尝试过
- traefik.frontend.rule=Host:${hostname},Host:www.${hostname},Host:autoconfig.${hostname}
或
- traefik.frontend.rule=Host:${hostname};Host:www.${hostname};Host:autoconfig.${hostname}
那没有用...
答案 0 :(得分:0)
回答我自己的问题(向dtomcej致谢,参考网址https://github.com/containous/traefik/issues/4904)
The issue you are encountering is that you have overlapping rules, and you are not defining any priority to determine order of rule execution.
From the documentation (https://docs.traefik.io/basics/#priorities):
By default, routes will be sorted (in descending order) using rules length
So since you have made the host rule much longer, and it matches, it is the first rule.
You can use the priority label to manually force the match of the portainer path first, before the base host match.
将traefik.frontend.priority = 1添加到我的Apache容器中,并将traefik.frontend.priority = 2添加到其他所有包含子路径的容器中。