Is it possible to expose the dashbaord under a sub-path of my domain?

Hello,

quick question here. I'm quite new to Traefik and would like to rather expose the Traefik dashboard under example.com/traefik rather than traefik.example.com.

I have tried a few options unsuccessfully so far. Furthermore, the documentation says:

As underlined in the documentation for the api.dashboard option, the router rule defined for Traefik must match the path prefixes /api and /dashboard .
We recommend to use a "Host Based rule" as Host(traefik.domain.com) to match everything on the host domain

So can I expose the dashboard (and the api) on a specific prefix or not at all ?

Thanks for the information!

There's good reason for that.

The application "dashboard" makes relative requests to /api and /dashboard from your client. So your path of /traefik will not work.

You might have misunderstood the word "MUST".

If you are concerned about security. Add basicAuth middleware to secure your dashboard.

Hello @jnovack and thanks for your prompt answer

No, no :slight_smile: but I must admit I have read the documentation in a random order and landed on this paragraph after I had already tried a few things and worked on my target setup.

That is kind of show stopper for me and I just wanted to be sure I really understood this:

The fact that I then must have specific registered FQDN for the dashboard only is too expensive in term of maintenance: my plan was to use Traefic in a setup with docker-compose that exposes a main service together with a DB, a Prometheus server and so on that I want to be able to deploy in one click for test purposes. And the main service has the same limitation than Traefik and must take control of the root of the path...

Can I know more about the deployment? I'm curious what makes it "too expensive"?

Are you using /api and /dashboard elsewhere? Why not leave those for traefik? It doesn't need to take CONTROL of the root of the path, it just needs to have /api and /dashboard.

rule = "PathPrefix(`/api`) || PathPrefix(`/dashboard`)"

You can still control the other near infinite possibilities (minus 2).

There's the other possibility using PathPrefixStrip on your other services.

Does that work for Prometheus and Grafana (et al.)?

In fact, that will do, thanks.

I've tried that before posting in the forum, but thought it does not work, because:

  • mydomain.com/api returns a 404 <= normal
  • mydomain.com/dashboard also returns a 404 <= normal when querying /dashboard (without the trailing slash) instead of /dashboard/ with the trailing slash. No comment...

About Prometheus for instance, yes it works, the server can be configured to expose the gathered metrics in a subpath of the FQDN, for those that might be insterrested, such a config works:

In docker-compose.yml file:

prometheus:
    image: prom/prometheus
    expose:
      - 9090
    volumes: 
      - prometheus_data:/prometheus
      - ./conf/prometheus.yml:/etc/prometheus/prometheus.yml
    command: 
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.path=/prometheus 
      - --storage.tsdb.retention.time=90d 
      - --web.external-url=https://${PUBLIC_FQDN}/prometheus
      - --web.listen-address=:9090
    labels:
      # Expose the metrics on the reserved sub path, TLS is provided by the Let's Encrypt cert provider.
      - traefik.enable=true
      - traefik.http.routers.prometheus.rule=Host(`${PUBLIC_FQDN}`)&&PathPrefix(`/prometheus`)
      - traefik.http.routers.prometheus.entrypoints=websecure
      - traefik.http.services.prometheus.loadbalancer.server.port=9090
      - traefik.http.routers.prometheus.tls.certresolver=leresolver  

The corresponding conf/prometheus.yml file:

- job_name: 'prometheus'
  metrics_path: '/prometheus/metrics'
  static_configs:
    - targets: ['localhost:9090']
http:
    routers:
        dashboard:
            ...
            service: dashboard@internal
            middlewares:
                - dashboard_redirect
                - dashboard_stripprefix
    middlewares:
        dashboard_redirect:
            redirectRegex:
                regex: "^(https:\\/\\/[^:\\/]+(:\\d+)?)\\/$"
                replacement: "${1}/dashboard/"
                permanent: true
        dashboard_stripprefix:
            stripPrefix:
                prefixes:
                    - "/dashboard/"
                    - "/dashboard"

I know... I know...

It was more that it is also in huge, bold, with big warnings a few times in the documentation.
But thanks for the tip though.

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