Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker traefik PathPrefix with StripPrefix Middleware always throws HTTP_502

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?

like image 324
tigu Avatar asked Jan 24 '20 13:01

tigu


1 Answers

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/
like image 134
Thomas Decaux Avatar answered Oct 22 '22 05:10

Thomas Decaux