traefiktraefik-routerstraefik-middleware

Traefik's StripPrefix with an app that doesn't support deployment on subdirectory


I have this app running on my homeserver that doesn't support a deployment on a subdirectory (e.g homeserver.local/app)

Checking the documentation for Traefik's StripPrefix middleware it says this:

Use a StripPrefix middleware if your backend listens on the root path (/) but should be exposed on a specific prefix.

IIUC, this is exactly my case: the app listens to / but I'd like to have it deployed on a path.

My current setup looks like this:

internet_speed:
  image: germannewsmaker/myspeed:1.0.9
  # port: 5216
  host: homeserver
  directories:
    - data:/myspeed/data
  env:
    TZ: Europe/Berlin
  labels:
    traefik.enable: true
    traefik.http.routers.internet_speed.rule: Host(`homeserver.local`) && PathPrefix(`/internet_speed`)
    traefik.http.routers.internet_speed.service: homeserver-internet-speed@docker
    traefik.http.middlewares.is_stripprefix.stripprefix.prefixes: /internet_speed
    traefik.http.routers.internet_speed.middlewares: is_stripprefix

and it doesn't work, the app requests some assets, and they point to / anyway:

enter image description here

maybe I have misunderstood the StripPrefix usage and the app has to support subdirectory deployment natively?


Solution

  • Most web apps do not support deployment under a path, but they need /. It's only possible when they support setting a dedicated "base path".

    You can update initial requests to Traefik and remove the path with middlewares (/myapp -> /), but the issue is that web apps respond with html that contains further resources like scripts, links and images. Those are usually fixed (example /static/script.js), therefore the next request from browser will not be routed to the right target, as /myapp is missing.

    Because of this using different sub-domains for services is best practice.