8
votes

I have a swarm service container, exposing port 5500. In the container, there is a web UI on https://localhost:5500/app. My service is called service1.

I am using a traefik 2 proxy and I want the web UI of my service1 to be available on https://proxy.domain.com/service1/app.

My traefik labels for service1 are configured like this:

labels:
  - "traefik.http.routers.service1.rule=Host(`proxy.domain.com`) && PathPrefix(`/service1/app`)"
  - "traefik.http.middlewares.strip-s1.stripprefix.prefixes=/service1"
  - "traefik.http.routers.service1.service=service1@docker"
  - "traefik.http.services.service1.loadbalancer.server.port=5500"
  - "traefik.http.routers.service1.middlewares=strip-s1@docker"
  - "traefik.http.routers.service1.entrypoints=https"
  - "traefik.http.routers.service1.tls=true"

As I understood traefik, with this configuration I can call https://proxy.domain.com/service1/app what matches the rule of the router. Traefik will then strip the /service1 from the pathPrefix, so /app will remain and be forwarded to the service container on port 5500, so I think the container will get called on port 5500/app.

But when I call https://proxy.domain.com/service1/app in my browser, I get HTTP_502 Bad gateway.

When I do curl -v https://proxy.domain.com/service1/app, I also get HTTP_502.

When I do curl -v https://proxy.domain.com:5500/app, it works and I connect to port 5500/app and get redirected to port 5500/app/login in the container (this redirect is done by the web application behind /app).

What am I doing wrong? Have I misconfigured my traefik labels?

2

2 Answers

4
votes

Not sure you must specify @docker, here a configuration that work with Traefik 2.2, and phpmyadmin as backend:

version: "2.4"

services:

  pma:
    image: phpmyadmin/phpmyadmin:latest
    labels:
    - "traefik.http.routers.pma.rule=Host(`admin.${DOMAIN}`) && PathPrefix(`/phpmyadmin`)"
    - "traefik.http.routers.pma.middlewares=pma-stripprefix"
    - "traefik.http.middlewares.pma-stripprefix.stripprefix.prefixes=/phpmyadmin"
    environment:
    - PMA_ABSOLUTE_URI=https://admin.${DOMAIN}/phpmyadmin/
-2
votes

I am neither a Traefik nor a Docker expert. But I have been looking into similar things. I think, the problem is, that stripprefix will strip the whole path and not just the part that you give in your label. From the v2.0 Traefik documentation of stripprefix:

For instance, /products would match /products but also /products/shoes and /products/shirts.

Since the path is stripped prior to forwarding, your backend is expected to listen on /.

Therefore, I think your Traefik router is not forwarding tohttps://proxy.domain.com:5500/app. You could set your Treafik logging to DEBUG and then check with docker logs traefik (or whatever your Traefik container is called) where the router is actually forwarding the request to.