I'm using Traefik to load balance across different services registered in Consul.
I'm using the consul-catalog configuration and overriding a front end routing rule for one of the services by adding a tag when defining the service in consul:
tags=[“traefik.frontend.rule=PathPrefixStrip:/api,Host:api.service.consul”]
I'm expecting both /api
and api.service.consul
to resolve to my service, however only /api
is successful, however api.service.consul
returns a 404 error.
In other words, only the first rule is being considered. If I switch the tag around:
tags=[“traefik.frontend.rule=Host:api.service.consul,PathPrefixStrip:/api”]
Then api.servie.consul
resolves and /api
returns a 404 error.
I believe the docs suggest this configuration is supported. Has anyone else had success with defining multiple rules via consul tags?
Edit: Since v1.7, for consul-catalog, you can use: multiple-frontends-for-a-single-service
tags=[
"traefik.frontends.foo.rule=Host:api.service.consul",
"traefik.frontends.bar.rule=PathPrefixStrip:/api",
]
The answer can be seen at https://github.com/containous/traefik/issues/2417:
,
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
) So, for your example, use:
tags=["traefik.frontend.rule=Host:api.service.consul;PathPrefixStrip:/api"]
Documentation links:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With