Unable to open traefik and service dashboard at subdirectory level

Below is a part of my config file. I can access the traefik dashboard at https://traefik.subdomain.domain and prometheus page at https://prometheus.subdomain.domain

However I want to access these pages at at subdirectory level, and not subdomain.
Something like:

https://subdomain.domain/traefik to get to traefik dashboard
https://subdomain.domain/prometheus to get to prometheus dashboard

I tried with "traefik.http.routers.traefik.rule=Host(`subdomain.domain`) && PathPrefix(`/traefik`)" to only get a 404 Page not found

version: '3'

services:
  traefik:
    image: traefik:v2.0
    command: 
      - --entryPoints.http.address=:80
      - --entryPoints.https.address=:443
      - --providers.docker.exposedByDefault=false
      - --accesslog=true 

    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock   
      - ./traefik/traefik.toml:/etc/traefik/traefik.toml
      - ./traefik/traefik.config.toml:/etc/traefik/traefik.config.toml
      - ./certs:/etc/certs
    labels:
      - "traefik.http.routers.traefik.rule=Host(`traefik.subdomain.domain}`)"
      - "traefik.http.routers.traefik.service=api@internal"
      - "traefik.http.routers.traefik.entrypoints=https"
      - "traefik.http.routers.traefik.tls=true"

  prometheus:
    image: prom/prometheus:latest
    ports:
      - 9090:9090
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --web.enable-lifecycle
    labels:
      - "traefik.enable=true"    
      - "traefik.http.routers.prometheus.rule=Host(`prometheus.subdomain.domain`)"
      - "traefik.http.routers.prometheus.entrypoints=https"
      - "traefik.http.routers.prometheus.tls=true" 

Appreciate the help.

I tried this for prometheus with url pointing to subdomain.domain/prometheus/, with no luck. The webpage gets redirected to /graph and then 404

- "traefik.http.routers.prometheus.rule=Host(`subdomain.domain`) && PathPrefix(`/prometheus/`)"
- "traefik.http.routers.prometheus.middlewares=prometheus-stripprefix"
- "traefik.http.middlewares.prometheus-stripprefix.stripprefix.prefixes=/prometheus"   

It's not gonna work if the underlying app does not support it. For traefik dashboard there is an issue here:https://github.com/containous/traefik/issues/5853 but as far as prometheus goes, if it does not support it, it's impossible.

version: '3'

services:
  traefik:
    image: traefik:v2.1.2
    command: >
      --api
      --entryPoints.http.address=:80
      --entryPoints.https.address=:443
      --providers.docker.exposedByDefault=false
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    labels:
      traefik.enable: true
      traefik.http.routers.traefik.rule: Host(`subdomain.localhost`) && (PathPrefix(`/traefik`) || PathPrefix(`/api`))
      traefik.http.routers.traefik.service: api@internal
      traefik.http.routers.traefik.entrypoints: https
      traefik.http.routers.traefik.tls: true
      traefik.http.routers.traefik.middlewares: strip

      traefik.http.middlewares.strip.stripprefix.prefixes: /traefik

  prometheus:
    image: prom/prometheus:v2.15.2
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --web.enable-lifecycle
      - --web.external-url=http://localhost:9090/prometheus/
    labels:
      traefik.enable: true
      traefik.http.routers.prometheus.rule: Host(`subdomain.localhost`) && PathPrefix(`/prometheus`)
      traefik.http.routers.prometheus.entrypoints: https
      traefik.http.routers.prometheus.tls: true
1 Like

Thanks Idez, it works as expected. On the same lines, do you know how this can be done for Grafana?

NVM, the link was helpful.