Metabase Behind Traefik

I am running metabase with docker compose and want to run it behind traefik in a subpath, so that it is running as /reporting.

I was able to successfully use Traefik & subpaths for keycloak & nginx for static assets, but there seems to be something causing issues with metabase doing this.

My traefik labels look like the following, and I've tried a variety of options here:


  • "traefik.enable=true"
  • ""
  • "traefik.http.routers.reporting.priority=100"
  • "traefik.http.routers.reporting.rule=PathPrefix(/reporting)"
  • ""
  • "traefik.http.middlewares.reporting.addprefix.prefix=/reporting"

And my docker-compose environment for metabase looks like:

  - MB_DB_TYPE=postgres
  - MB_DB_HOST=metabase_db
  - MB_DB_PORT=5432
  - MB_DB_USER=metabase
  - MB_DB_PASS=passwordhere

I've tried variations of setting the app url in the metabase settings to / and /reporting, and both fail.

What is happening is I go to /reporting in a browser, and then I get a blank page with metabase header, and it attempting to go to /app/.... instead of /reporting/app/... for assets.

When using PathPrefix(`/reporting`), all requests to /reporting will be forwarded to your target server, including the path /reporting. So your target server needs to respond to /reporting, are you sure that is happening?

With this line you would just add another /reporting to the path: addprefix.prefix=/reporting

Yes that should be the case, I set the metabase config to /reporting in one instance and removed the addprefix and it still acted the same way.

I saw that someone was able to get it working with nginx: Allow Metabase to work on sub paths · Issue #30895 · metabase/metabase · GitHub

But not sure how to translate that to traefik.

If I understand the nginx config correctly, it will actually do an addprefix with /metabase.

Be aware you need to create and assign the addprefix middlewares, see doc (link).

Hi d10sfan,

You could try adding MB_SITE_URL=https://yourdomain/reporting to your Metabase environment configuration.
See Metabase documentation -> environment variables

I agree with bluepuma77 that adding the prefix as a middleware does not help in this case (BTW, I'd say it has no effect in your current configuration, because you're defining the middleware with the traefik.http.middlewares.reporting.addprefix.prefix=/reporting label, but you're not assigning it to the router (which would be done with an additional line like traefik.http.routers.reporting.middlewares=reporting).

Metabase runs great with behind Traefik. I use it on a dedicated subdomain, so my suggestion is not tested.

Thanks for the responses!

It seems the unique thing with my issues is the subpath, thanks for the detailsa bout the middleware assignment to the router, as I missed that.

I tried doing the following in docker compose:

    image: metabase/metabase:latest
    restart: always
      - metabase_db
      - MB_DB_TYPE=postgres
      - MB_DB_HOST=metabase_db
      - MB_DB_PORT=5432
      - MB_DB_USER=metabase
      - MB_DB_PASS=passwordhere
      - MB_SITE_URL=https://localhost:8088/reporting
      - MB_ENCRYPTION_SECRET_KEY=secretkey
      - "traefik.enable=true"
      - ""
      - "traefik.http.routers.reporting.priority=100"
      - "traefik.http.routers.reporting.rule=PathPrefix(`/reporting`)"
      - ""
      - "traefik.http.middlewares.reporting.addprefix.prefix=/reporting"
      - "traefik.http.routers.reporting.middlewares=reporting"

I tried both with and without the addprefix portion, and metabase is still failing. It seems like there's code that's rewriting the metabase url on the metabase side.

This shows the behavior, you can see in the console the error and then it's attempting to go to /app... instead of /reporting/app

I don't know your Traefik configuration, so I only can make some assuptions.

You have set - MB_SITE_URL=https://localhost:8088/reporting with https - in the console it seems you use http without the 's' / unencrypted.

Can you access Metabase without Traefik? In the administration menu you also can configure the base URL.

Are you using Traefik 2 or Traefik 3? If you're using Traefik Beta v3.0 you might need the middleware for content-type autodetection.

Ah good catch, I incorrectly had it at https when it should be http, but the behavior is unchanged (I had set it before to http in past tests as well with no results).

And yes, if I open the port, I can access it fine, but changing it in the dashboard also does not help.

I'm using trafeik 2, my trafeik container looks like the following:

    image: traefik:v2.10
    command: --accesslog=true --providers.docker --providers.docker.exposedByDefault=false
      - "8088:80"
      - /var/run/docker.sock:/var/run/docker.sock

How about you expose your metabase port directly and test first if it works and which path to use, before placing Traefik in front.

I tried that and set the MB_SITE_URL to the port and /reporting, so http://localhost:8082/reporting and metabase is not running at /reporting but the root, so it does not seem to be listening to that, at least without a proxy in front. I can access it fine at http://localhost:8082, so it isnt using the parameter given.

and seeing this in the js logs:

Warning: the Metabase site URL basename "/reporting/" does not match the actual basename "/".

You can expect Metabase help in a Traefik forum :wink:

If you insist using a PathPrefix to access it over Traefik, and it's a pure API, no GUI with links, the you can use stripprefix middleware (doc) to remove reportingwhen the request is forwarded internally.

You can use something like whoami (link) to test if your middlewares are working correctly. See simple Traefik example.

Yeah Ive used middleware and have successfully gotten other services working behind trafeik just fine (keycloak, nginx, and a custom backend for example). I'll probably look at a different reporting tool as a solution. I did create a thread over at metabase but haven't seen a response.

I ended up switching to grafana instead, as it was easy to setup and supported sub paths much better.

The docker container in compose ended up being:

    image: grafana/grafana-oss:9.5.15
    restart: always
      - grafana_db
      GF_DATABASE_TYPE: postgres
      GF_DATABASE_HOST: grafana_db:5432
      GF_DATABASE_NAME: grafana
      GF_DATABASE_USER: grafana
      GF_DATABASE_PASSWORD: passwordhere
      GF_DATABASE_SSL_MODE: disable
      GF_SECURITY_ADMIN_PASSWORD: passwordhere
      GF_SERVER_DOMAIN: localhost
      GF_SERVER_ROOT_URL: http://localhost:8088/reporting/
      GF_ENABLE_GZIP: true
      - "traefik.enable=true"
      - ""
      - "traefik.http.routers.reporting.priority=100"
      - "traefik.http.routers.reporting.rule=PathPrefix(`/reporting`)"
      - ""
      - ./grafana-data:/var/lib/grafana
      - ./resources/grafana-provisioning:/etc/grafana/provisioning

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.