简体   繁体   English

traefik docker标签中基于主机和路径的路由规则的混合

[英]Mixture of host and path based routing rules in traefik docker labels

I'm trying to create a frontend rule using docker labels that directs both a couple host based routes and some path based routes from a domain to one backend but I'm having trouble getting the right magic for what turn out to be kind of complex rules. 我正在尝试使用docker标签创建一条前端规则,该规则将一对基于主机的路由以及一些基于路径的路由从一个域定向到一个后端,但是我很难找到正确的魔术来解决复杂的问题规则。

frontend.rule="Host:HostA.domain,HostB.domain,HostC.domain,Host:svc.domain;PathPrefix=/api/users, Host:svc.domain;PathPrefix=/api/other"

This seemed like the right combination of or and And logic but I seem to be wrong. 这似乎是orAnd逻辑的正确组合,但我似乎错了。

  • , is the OR operator (works only inside a matcher, ex: Host:foo.com,bar.com ) ,是OR运算符(仅在匹配器中有效,例如: Host:foo.com,bar.com
  • ; is the AND operator (works only between matchers, ex: Host:foo.com;Path:/bar ) 是AND运算符(仅在匹配器之间起作用,例如: Host:foo.com;Path:/bar

Host:api.service;PathPrefixStrip:/foo

To have a OR between matchers you need to use segment labels: 要使匹配器之间具有OR,您需要使用细分标签:

   # ...
   labels:
     - "traefik.enable=true"
     - "traefik.port=80"
     - "traefik.foo.frontend.rule=Host:api.mydomain.com"
     - "traefik.bar.frontend.rule=Host:www.mydomain.com,m.mydomain.com;PathPrefixStrp:/_"
   # ...

Documentation links: 文档链接:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM