简体   繁体   中英

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.

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.

  • , is the OR operator (works only inside a matcher, ex: Host:foo.com,bar.com )
  • ; is the AND operator (works only between matchers, ex: Host:foo.com;Path:/bar )

Host:api.service;PathPrefixStrip:/foo

To have a OR between matchers you need to use segment labels:

   # ...
   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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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