For the newbies among us:
When you request a URL from Traefik, like example.com/app
, you can route by domain and (optional) path. When Traefik is forwarding to the target service, the path will be re-used (GET /app
). So your target service needs to respond to this specific path.
You can use stripprefix
middleware, to remove the path from the forwarding request. This works great with API apps, that only use a single request.
Usually modern web apps will need a lot of dependencies, like /static/script.js
and /img/logo.jpg
. Those are linked with absolute path from the initial page you load. So even if you get external path /app
to load the first page, the browser will then try to load /static/script.js
, to which Traefik can not route with path /app
.
So if path based routing should work with a web app, you need to tell it to respond to the desired path, with the initial start page and also with all required dependencies.
Best practice is to use sub-domains, so you don't need to mess with path settings inside the web app - and sometimes its not even possible.
Two examples:
- Traefik dashboard is fixed to
/dashboard
, this can't never be changed. - Wordpress can be configured to use a
/app
by setting a "base path".