Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traefik not routing path correctly #1037

Closed
Mr-Right2 opened this issue Jan 13, 2017 · 5 comments
Closed

Traefik not routing path correctly #1037

Mr-Right2 opened this issue Jan 13, 2017 · 5 comments
Labels
Milestone

Comments

@Mr-Right2
Copy link

Mr-Right2 commented Jan 13, 2017

What version of Traefik are you using (traefik version)?

v1.1.2 / camembert

What is your environment & configuration (arguments, toml...)?

Ubuntu 16.04 with Docker version 1.12.5 and docker-compose version 1.9.0
No toml configuration used (see docker-compose yml below)

What did you do?

I started one whoamI and a few (five) Portainer containers. My goal is to have a container available at a certain path; whoamI should be available at <myIP>/wai and Portainer <myIP>/portainer. I'm not exactly sure which frontend rule I need to achieve this (Path, PathPrefix, PathStrip or PathPrefixStrip) but I would assume it should be just the Path one. Below is my docker-compose file in which I tried all posibilities.

docker-compose.yml:

version: '2'

services:
  traefik:
    container_name: traefik
    image: traefik
    command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /dev/null:/traefik.toml
    labels:
        - "traefik.enable=false"
  whoami:
    image: emilevauge/whoami
    labels:
      - "traefik.backend=whoami"
      - "traefik.frontend.rule=Path: /wai/"
  portainer1:
    image: portainer/portainer
    labels:
      - "traefik.backend=portainer1"
      - "traefik.frontend.rule=Path: /portainer1/"
  portainer2:
    image: portainer/portainer
    labels:
      - "traefik.backend=portainer2"
      - "traefik.frontend.rule=PathStrip: /portainer2/"
  portainer3:
    image: portainer/portainer
    labels:
      - "traefik.backend=portainer3"
      - "traefik.frontend.rule=PathPrefix: /portainer3/"
  portainer4:
    image: portainer/portainer
    labels:
      - "traefik.backend=portainer4"
      - "traefik.frontend.rule=PathPrefixStrip: /portainer4/"
  portainer:
    image: portainer/portainer
    ports:
      - "9000:9000"
    labels:
        - "traefik.enable=false"

Traefik startup logs:

time="2017-01-13T14:14:22Z" level=info msg="Traefik version v1.1.2 built on 2016-12-15_10:21:15AM"
time="2017-01-13T14:14:22Z" level=info msg="Using TOML configuration file //traefik.toml"
time="2017-01-13T14:14:22Z" level=debug msg="Global configuration loaded {\"GraceTimeOut\":10,\"Debug\":false,\"CheckNewVersion\":true,\"AccessLogsFile\":\"\",\"TraefikLogsFile\":\"\",\"LogLevel\":\"DEBUG\",\"EntryPoints\":{\"http\":{\"Network\":\"\",\"Address\":\":80\",\"TLS\":null,\"Redirect\":null,\"Auth\":null,\"Compress\":false}},\"Cluster\":null,\"Constraints\":[],\"ACME\":null,\"DefaultEntryPoints\":[\"http\"],\"ProvidersThrottleDuration\":2000000000,\"MaxIdleConnsPerHost\":200,\"InsecureSkipVerify\":false,\"Retry\":null,\"Docker\":{\"Watch\":true,\"Filename\":\"\",\"Constraints\":null,\"Endpoint\":\"unix:///var/run/docker.sock\",\"Domain\":\"docker.localhost\",\"TLS\":null,\"ExposedByDefault\":true,\"UseBindPortIP\":false,\"SwarmMode\":false},\"File\":null,\"Web\":{\"Address\":\":8080\",\"CertFile\":\"\",\"KeyFile\":\"\",\"ReadOnly\":false,\"Auth\":null},\"Marathon\":null,\"Consul\":null,\"ConsulCatalog\":null,\"Etcd\":null,\"Zookeeper\":null,\"Boltdb\":null,\"Kubernetes\":null,\"Mesos\":null}"
time="2017-01-13T14:14:22Z" level=info msg="Preparing server http &{Network: Address::80 TLS:<nil> Redirect:<nil> Auth:<nil> Compress:false}"
time="2017-01-13T14:14:22Z" level=info msg="Starting provider *provider.Docker {\"Watch\":true,\"Filename\":\"\",\"Constraints\":null,\"Endpoint\":\"unix:///var/run/docker.sock\",\"Domain\":\"docker.localhost\",\"TLS\":null,\"ExposedByDefault\":true,\"UseBindPortIP\":false,\"SwarmMode\":false}"
time="2017-01-13T14:14:22Z" level=info msg="Starting provider *main.WebProvider {\"Address\":\":8080\",\"CertFile\":\"\",\"KeyFile\":\"\",\"ReadOnly\":false,\"Auth\":null}"
time="2017-01-13T14:14:22Z" level=info msg="Starting server on :80"
time="2017-01-13T14:14:22Z" level=debug msg="Docker connection established with docker 1.12.5 (API 1.24)"
time="2017-01-13T14:14:22Z" level=debug msg="Filtering disabled container /portainer_portainer_1"
time="2017-01-13T14:14:22Z" level=debug msg="Filtering disabled container /traefik"
time="2017-01-13T14:14:22Z" level=debug msg="Load balancer method '<nil>' for backend backend-portainer3: Invalid method, using default. Using default wrr."
time="2017-01-13T14:14:22Z" level=debug msg="Load balancer method '<nil>' for backend backend-portainer4: Invalid method, using default. Using default wrr."
time="2017-01-13T14:14:22Z" level=debug msg="Load balancer method '<nil>' for backend backend-whoami: Invalid method, using default. Using default wrr."
time="2017-01-13T14:14:22Z" level=debug msg="Load balancer method '<nil>' for backend backend-portainer1: Invalid method, using default. Using default wrr."
time="2017-01-13T14:14:22Z" level=debug msg="Load balancer method '<nil>' for backend backend-portainer2: Invalid method, using default. Using default wrr."
time="2017-01-13T14:14:22Z" level=debug msg="Configuration received from provider docker: {\"backends\":{\"backend-portainer1\":{\"servers\":{\"server-portainer_portainer1_1\":{\"url\":\"http://172.19.0.4:9000\",\"weight\":0}},\"loadBalancer\":{\"method\":\"wrr\"}},\"backend-portainer2\":{\"servers\":{\"server-portainer_portainer2_1\":{\"url\":\"http://172.19.0.7:9000\",\"weight\":0}},\"loadBalancer\":{\"method\":\"wrr\"}},\"backend-portainer3\":{\"servers\":{\"server-portainer_portainer3_1\":{\"url\":\"http://172.19.0.5:9000\",\"weight\":0}},\"loadBalancer\":{\"method\":\"wrr\"}},\"backend-portainer4\":{\"servers\":{\"server-portainer_portainer4_1\":{\"url\":\"http://172.19.0.3:9000\",\"weight\":0}},\"loadBalancer\":{\"method\":\"wrr\"}},\"backend-whoami\":{\"servers\":{\"server-portainer_whoami_1\":{\"url\":\"http://172.19.0.2:80\",\"weight\":0}},\"loadBalancer\":{\"method\":\"wrr\"}}},\"frontends\":{\"frontend-Path-portainer1\":{\"entryPoints\":[\"http\"],\"backend\":\"backend-portainer1\",\"routes\":{\"route-frontend-Path-portainer1\":{\"rule\":\"Path: /portainer1/\"}},\"passHostHeader\":true,\"priority\":0},\"frontend-Path-wai\":{\"entryPoints\":[\"http\"],\"backend\":\"backend-whoami\",\"routes\":{\"route-frontend-Path-wai\":{\"rule\":\"Path: /wai/\"}},\"passHostHeader\":true,\"priority\":0},\"frontend-PathPrefix-portainer3\":{\"entryPoints\":[\"http\"],\"backend\":\"backend-portainer3\",\"routes\":{\"route-frontend-PathPrefix-portainer3\":{\"rule\":\"PathPrefix: /portainer3/\"}},\"passHostHeader\":true,\"priority\":0},\"frontend-PathPrefixStrip-portainer4\":{\"entryPoints\":[\"http\"],\"backend\":\"backend-portainer4\",\"routes\":{\"route-frontend-PathPrefixStrip-portainer4\":{\"rule\":\"PathPrefixStrip: /portainer4/\"}},\"passHostHeader\":true,\"priority\":0},\"frontend-PathStrip-portainer2\":{\"entryPoints\":[\"http\"],\"backend\":\"backend-portainer2\",\"routes\":{\"route-frontend-PathStrip-portainer2\":{\"rule\":\"PathStrip: /portainer2/\"}},\"passHostHeader\":true,\"priority\":0}}}"
time="2017-01-13T14:14:22Z" level=debug msg="Last docker config received more than 2s, OK"
time="2017-01-13T14:14:22Z" level=debug msg="Creating frontend frontend-Path-portainer1"
time="2017-01-13T14:14:22Z" level=debug msg="Wiring frontend frontend-Path-portainer1 to entryPoint http"
time="2017-01-13T14:14:22Z" level=debug msg="Creating route route-frontend-Path-portainer1 Path: /portainer1/"
time="2017-01-13T14:14:22Z" level=debug msg="Creating backend backend-portainer1"
time="2017-01-13T14:14:22Z" level=debug msg="Creating load-balancer wrr"
time="2017-01-13T14:14:22Z" level=debug msg="Creating server server-portainer_portainer1_1 at http://172.19.0.4:9000 with weight 0"
time="2017-01-13T14:14:22Z" level=debug msg="Creating frontend frontend-Path-wai"
time="2017-01-13T14:14:22Z" level=debug msg="Wiring frontend frontend-Path-wai to entryPoint http"
time="2017-01-13T14:14:22Z" level=debug msg="Creating route route-frontend-Path-wai Path: /wai/"
time="2017-01-13T14:14:22Z" level=debug msg="Creating backend backend-whoami"
time="2017-01-13T14:14:22Z" level=debug msg="Creating load-balancer wrr"
time="2017-01-13T14:14:22Z" level=debug msg="Creating server server-portainer_whoami_1 at http://172.19.0.2:80 with weight 0"
time="2017-01-13T14:14:22Z" level=debug msg="Creating frontend frontend-PathPrefix-portainer3"
time="2017-01-13T14:14:22Z" level=debug msg="Wiring frontend frontend-PathPrefix-portainer3 to entryPoint http"
time="2017-01-13T14:14:22Z" level=debug msg="Creating route route-frontend-PathPrefix-portainer3 PathPrefix: /portainer3/"
time="2017-01-13T14:14:22Z" level=debug msg="Creating backend backend-portainer3"
time="2017-01-13T14:14:22Z" level=debug msg="Creating load-balancer wrr"
time="2017-01-13T14:14:22Z" level=debug msg="Creating server server-portainer_portainer3_1 at http://172.19.0.5:9000 with weight 0"
time="2017-01-13T14:14:22Z" level=debug msg="Creating frontend frontend-PathPrefixStrip-portainer4"
time="2017-01-13T14:14:22Z" level=debug msg="Wiring frontend frontend-PathPrefixStrip-portainer4 to entryPoint http"
time="2017-01-13T14:14:22Z" level=debug msg="Creating route route-frontend-PathPrefixStrip-portainer4 PathPrefixStrip: /portainer4/"
time="2017-01-13T14:14:22Z" level=debug msg="Creating backend backend-portainer4"
time="2017-01-13T14:14:22Z" level=debug msg="Creating load-balancer wrr"
time="2017-01-13T14:14:22Z" level=debug msg="Creating server server-portainer_portainer4_1 at http://172.19.0.3:9000 with weight 0"
time="2017-01-13T14:14:22Z" level=debug msg="Creating frontend frontend-PathStrip-portainer2"
time="2017-01-13T14:14:22Z" level=debug msg="Wiring frontend frontend-PathStrip-portainer2 to entryPoint http"
time="2017-01-13T14:14:22Z" level=debug msg="Creating route route-frontend-PathStrip-portainer2 PathStrip: /portainer2/"
time="2017-01-13T14:14:22Z" level=debug msg="Creating backend backend-portainer2"
time="2017-01-13T14:14:22Z" level=debug msg="Creating load-balancer wrr"
time="2017-01-13T14:14:22Z" level=debug msg="Creating server server-portainer_portainer2_1 at http://172.19.0.7:9000 with weight 0"
time="2017-01-13T14:14:22Z" level=info msg="Server configuration reloaded on :80"

What did you expect to see?

I would expect the whoamI webserver to be available at <myIP>/wai and Portainer to be available at `/portainer1.

What did you see instead?

As can be seen in the in the attachment below, whoamI is reachable and works as it should. Portainer, however, cannot be reached at <myIP>/portainer1 (I get a 404 page not found). Instead I am able to reach (parts of) it at <myIP>/portainer2. As can be seen below, a white page is shown instead of the Portainer interface (shown bottom right for reference).

image

It might be worth noting that navigating to <myIP>/portainer4/ (but not <myIP>/portainer4) shows the same white page as when navigating to <myIP>/portainer2. There is, however, a noticable difference between these two: When the (white) Portainer page is loaded when navigating to <myIP>/portainer2, only line is shown in the Traefik log (see below). When navigating to Portainer via <myIP>/portainer4, three extra lines show up in the log indicating a 400 status. After some investigation, I found out that this comes from my browser's attempt to load additional files (i.e. a javascript file, a favicon and a stylesheet). So, when accessing Portainer at <myIP>/portainer4/ my browser apparently knows it needs to fetch those extra files and tries to do so (which does not happen when navigating to <myIP>/portainer2). When trying to access the files myself by, for example, navigating to <myIP>/portainer4/ico/favicon.ico, I get a 400 Bad Request. Lastly, when navigating to <myIP>/portainer2/ico/favicon.ico is see a 404 page not found.

So based on these results I'm wondering:

  • Why I cannot reach Portainer at <myIP>/portainer1 but instead on <myIP>/portainer2
  • Why I do not see the full Portainer page when navigating to <myIP>/portainer2
  • Why there is a difference in behavior between accessing a file (e.g. the favicon) between <myIP>/portainer2/ and <myIP>/portainer4/
  • What the 400 Bad Request actually means and if/how this problem this problem can be fixed

Maybe it would be nice if Traefik can generate some more detailed logging on how it routes traffic to containers since the logging (at debug level) is still a bit scarce.

Additional Traefik logging generated after visiting <myIP>/wai, <myIP>/portainer1/, <myIP>/portainer2/, <myIP>/portainer3/ and <myIP>/portainer4/, respectively:

time="2017-01-13T14:33:16Z" level=debug msg="Round trip: http://172.19.0.2:80, code: 200, duration: 1.000627ms"
time="2017-01-13T14:33:22Z" level=debug msg="Round trip: http://172.19.0.7:9000, code: 404, duration: 1.006089ms"
time="2017-01-13T14:33:24Z" level=debug msg="Round trip: http://172.19.0.3:9000, code: 200, duration: 1.160158ms"
time="2017-01-13T14:33:26Z" level=debug msg="Round trip: http://172.20.0.5:9000, code: 404, duration: 1.291309ms"
time="2017-01-13T14:33:29Z" level=debug msg="Round trip: http://172.20.0.4:9000, code: 200, duration: 2.788462ms"
time="2017-01-13T14:33:29Z" level=debug msg="Round trip: http://172.20.0.4:9000, code: 400, duration: 777.073µs"
time="2017-01-13T14:33:30Z" level=debug msg="Round trip: http://172.20.0.4:9000, code: 400, duration: 1.780621ms"
time="2017-01-13T14:33:30Z" level=debug msg="Round trip: http://172.20.0.4:9000, code: 400, duration: 1.780341ms"

My Traefik dashboard:
image

Solution
Finally found the solution. The correct approach in cases like these should be to use the PathPrefixStrip rule. However, as mentioned in #374, putting a / at the end of the rule will break the setup. I created a working configuration by removing / at the end of the PathPrefixStrip: /portainer4/ rule. So this docker-compose configuration worked for me:

version: '2'

services:
  traefik:
    container_name: traefik2
    image: traefik
    command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG
    ports:
      - "80:80"
      - "8081:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /dev/null:/traefik.toml
    labels:
        - "traefik.enable=false"
  portainer:
    image: portainer/portainer
    labels:
      - "traefik.backend=portainer"
      - "traefik.frontend.rule=PathPrefixStrip: /portainer"

Now when I navigate to <myIP>/portainer/ I see the portainer page.
Note: I still get the white page as mentioned earlier when I navigate to <myIP>/portainer.

@nsteinmetz
Copy link

Interested also as I had the same issue yesterday ; I only tried the Path rule like below which did not work:

    labels:
      - "traefik.backend=portainer1"
      - "traefik.frontend.rule=Path: /portainer1/"

@Mr-Right2
Copy link
Author

@nsteinmetz See my update. Apparently this #374 was part of the problem.

@nsteinmetz
Copy link

@Mr-Right2 thanks for the update ; in fact, on my real sample, I removed the ending slash.

I should have copied to be consistent with my case:

labels:
      - "traefik.backend=portainer1"
      - "traefik.frontend.rule=Path:/portainer1"

Will double check anyway !

@dannydulai
Copy link

@Mr-Right2's solution worked for me (removing the trailing / from the PathPrefixStrip), but it is not ideal that /portainer just leads to badness.

@ldez ldez added bug kind/bug/confirmed a confirmed bug (reproducible). and removed bug labels Apr 22, 2017
@ldez ldez added this to the 1.3 milestone May 24, 2017
@ldez
Copy link
Member

ldez commented May 24, 2017

Closed by #1638, in the version 1.3.0-rc3.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants