Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues with Path and PathPrefix matching in Traefik

Tags:

traefik

Using Traefix version 1.2.3 from the docker container I've set up the following file.

traefik:
  image: traefik
  command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG
  ports:
    - "80:80"
    - "8080:8080"
    - "443:443"
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - /dev/null:/traefik.toml  

services:
  image: opencoredata/ocdservices:0.2
  labels:
    - "traefik.backend=services"
    - "traefik.frontend.rule=Host:opencore.dev"
    - "traefik.frontend.rule=PathPrefix:/api"

# web:
#   image: opencoredata/ocdweb:0.3
#   labels:
#     - "traefik.backend=web"
#     - "traefik.frontend.rule=Host:opencore.dev"

If I remove the comments around the "web" section all traffic will go to that container ignoring the Path or PathPrefix or any other attempt to get URLs with the beginning /api/ to go to the services container.

Commenting out the "web" container like above and the traffic goes to the services container. Which is expected since there is no other container of course.

I simply can not find how to get Traefik to work with Path, PathPrefix, PathPrefixStrip or any other combination. Examples here and in the docs seem to indicate I should get the behavior I want, but I can not realize it.

like image 833
Douglas Fils Avatar asked May 01 '17 14:05

Douglas Fils


1 Answers

I think that this part

- "traefik.frontend.rule=Host:opencore.dev"
- "traefik.frontend.rule=PathPrefix:/api"

is wrong because second line overwrite the first one, try this :

- "traefik.frontend.rule=Host:opencore.dev;PathPrefix:/api"

I think it will combine stuff the way you want.

like image 143
papey Avatar answered Nov 18 '22 19:11

papey