Traefik,multiple frontend rules to one docker container
Traefik,multiple frontend rules to one docker container
I did search the manual but really couldn't make it very clear, even using the keywords to google that.
I need to proxy the /_
to the API container, some rule like that www.mydomain.com/_ => API container
/_
www.mydomain.com/_ => API container
There is already a specified domain point to this API containerapi.mydomain.com => API container
api.mydomain.com => API container
This is my docker-compose.yml
, all I want is to add a rule that proxy the /_
to this container too.
docker-compose.yml
/_
version: '3.3'
services:
testapi:
image: git.xxxx.com/api/core/test:latest
restart: always
networks:
- web
- default
expose:
- "80"
labels:
- "traefik.enable=true"
- "traefik.port=80"
- "traefik.docker.network=web"
- "traefik.backend=testapi"
#this domain is used for app
- "traefik.frontend.rule=Host:api.test.mydomain.com"
#this is used for website.All I want is prxy "https://www.test.mydomain.com/_/" to this container
- "traefik.frontend.rule1=Host:www.test.mydomain.com;PathPrefixStrp:/_"
1 Answer
1
You can use segment labels:
version: '3.3'
services:
testapi:
image: git.xxxx.com/api/core/test:latest
restart: always
networks:
- web
- default
expose:
- "80"
labels:
- "traefik.enable=true"
- "traefik.port=80"
- "traefik.docker.network=web"
#this domain is used for app
- "traefik.foo.frontend.rule=Host:api.test.mydomain.com"
- "traefik.bar.frontend.rule=Host:www.test.mydomain.com,m.test.mydomain.com;PathPrefixStrp:/_"
https://docs.traefik.io/v1.6/configuration/backends/docker/#on-containers-with-multiple-ports-segment-labels
Bravo man! Saved my time.
– Taras Vaskiv
Nov 8 '18 at 18:39
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Work like a charm
– wanfujinan
Sep 12 '18 at 2:13