Multiple services under the same domain name

I have two applications/containers where I want them to be exposed in the same domain (with SSL) but at different routes and I'm facing an issue on the second app as it recognizes the extra prefix route as an application internal and returns a typical 404 error.

My setup:

App A

apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: app
  namespace: app-ns
spec:
  entryPoints:
    - websecure
  routes:
    - match: Host(`app.example.com`) && PathPrefix(`/`)
      kind: Rule
      services:
        - name: app
          port: 80
  tls:
    secretName: app-example-com-tls

App B

apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: rstudio
  namespace: app-ns
spec:
  entryPoints:
    - websecure
  routes:
    - match: Host(`app.example.com`) && PathPrefix(`/user`)
      kind: Rule
      services:
        - name: rstudio
          port: 8787
      middlewares:
      - name: rstudio
  tls:
    secretName: app-example-com-tls

App B Middleware

apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: rstudio
  namespace: app-ns
spec:
  addPrefix:
    prefix: /user

When navigating to "app.example.com/user" I get the below page coming from the App B (rocker/rstudio image):

image

You can not simply place a web app under a path prefix.

GUI web apps will mostly respond with redirects, scripts, images and links with absolute paths, based on root (/js/script.js), so those won’t work with path prefix.

It only works when you can set some kind of "base path" in the configuration of your app.

Otherwise follow best practice and use sub-domains.

I see, this is what I was thinking too but I thought that Traefik can just redirect an app to a new subpath that you can define.

Thanks!

Well, Traefik can route by PathPrefix and it can even remove the path with a middleware, so it looks ok to the target app. This works for API apps.

But when you have GUI web apps that respond with fixed absolute paths for further content or dependencies to the browser, there is nothing Traefik can do.

1 Like