Search code examples
dockerwebservergrafanatraefik

Why do my configurations of Grafana, Docker and Traefik not route my requests to Grafana's frontpage?


I am new to traefik and am trying to set up my containers to be reverse-proxied by traefik at the moment. It all worked fine while using traefik.frontend.rule=Host:grafana01.mydomain.com for routing requests to grafana01.mydomain.com, but due to infrastructural issues within our network I'd rather use traefik.frontend.rule=Path:/grafana01/ to redirect to mydomain.com/grafana01. Yet for some reason it does not work. My traefik.toml file as well as my two docker-compose.yml files for traefik and grafana, respectively:

#Traefik Global Configuration
debug = false
checkNewVersion = true
logLevel = "ERROR"

#Define the EntryPoint for HTTP and HTTPS
defaultEntryPoints = ["https","http"]

#Enable Traefik Dashboard on port 8080
[web]
address = ":8080"

#Define the HTTP port 80 and
#HTTPS port 443 EntryPoint
#Enable automatically redirect HTTP to HTTPS
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]

#Enable retry sending a request if the network error
[retry]

#Define Docker Backend Configuration
[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "mydomain.com"
watch = true

#Letsencrypt Registration
#Define the Letsencrypt ACME HTTP challenge
[acme]
email = "some_email"
storage = "acme.json"
entryPoint = "https"
OnHostRule = true
  [acme.httpChallenge]
  entryPoint = "http"
version: '3'

services:
  traefik:
    image: traefik:latest
    command: --docker --docker.mydomain.com
    ports:
      - 80:80
      - 443:443
    networks:
      - traefik
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik.toml:/traefik.toml
      - ./acme.json:/acme.json
    labels:
      - "traefik.frontend.rule=Host:mydomain.com"
      - "traefik.port=8080"
      - "traefik.backend=traefik"
    container_name: traefik
    restart: always

networks:
  traefik:
    external: true
version: '3'

services:
  grafana01:
    image: grafana/grafana
    labels:
      - traefik.port=3000
      - traefik.backend=grafana01
      - traefik.frontend.rule=Path:/grafana01/
      - traefik.docker.network=traefik
    networks:
      - traefik
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=secret
    volumes:
      - /srv/docker/grafana01/data:/var/lib/grafana
    container_name: grafana01
    restart: always

  grafana02:
    image: grafana/grafana
    labels:
      - traefik:port=3001
      - traefik.backend=grafana02
      - traefik.frontend.rule=Path:/grafana02/
      - traefik.docker.network=traefik
      - traefik.enable=true
    networks:
      - traefik
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=secret
    volumes:
      - /srv/docker/grafana02/data:/var/lib/grafana
    container_name: grafana02
    restart: always

networks:
  traefik:
    external: true

I'd appreciate any help!


Solution

  • Changing traefik.frontend.rule=Path:/grafana01/ to traefik.frontend.rule=PathPrefixStrip:/grafana01 as well as adding GF_SERVER_ROOT_URL=%(protocol)s://%(domain)s/grafana01 did the trick for me.