简体   繁体   中英

Traefik dasboard not working with subdomain

I am trying to setup Traefik dashboard under a subdomain, but I am getting 404 page not found. However, I can access the api without any problems. Below is the docker-compose.yml that I have created.

version: '3.7'
services:
  traefik:
    image: traefik:v2.9.6
    container_name: traefik
    hostname: traefik
    restart: always
    ports:
      - 80:80
      - 8080:8080
    command:
      - --api.insecure=true
      - --api.dashboard=true
      - --api.debug=true
      - --log.level=DEBUG
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --providers.docker.network=traefikweb
      - --entrypoints.web.address=:80
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - traefikweb
    labels:
      - traefik.enable=true
      - traefik.http.routers.dashboard.rule=Host(`traefik.example.com`) && PathPrefix(`/dashboard`)
      - traefik.http.routers.dashboard.service=dashboard@internal
      - traefik.http.routers.dashboard.entrypoints=web
      - traefik.http.routers.api.rule=Host(`traefik.example.com`) && PathPrefix(`/api`)
      - traefik.http.routers.api.service=api@internal
      - traefik.http.routers.api.entrypoints=web
networks:
  traefikweb:
    external: true

I need guidance what I am doing wrong and why traefik.example.com/api/rawdata works and traefik.example.com/dashboard won't. Thanks

My solution based on larsks answer:

version: '3.7'
services:
  traefik:
    image: traefik:v2.9.6
    container_name: traefik
    hostname: traefik
    restart: always
    ports:
      - 80:80
    command:
      - --api.insecure=true
      - --api.dashboard=true
      - --api.debug=true
      - --log.level=DEBUG
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --providers.docker.network=traefikweb
      - --entryPoints.web.address=:80
      - --accessLog.filePath=/dev/stderr
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - traefikweb
    labels:
      - traefik.enable=true

      - traefik.http.routers.dashboard.rule=Host(`traefik.example.com`)
      - traefik.http.routers.dashboard.service=dashboard@internal
      - traefik.http.routers.dashboard.entrypoints=web

      - traefik.http.routers.api.rule=Host(`traefik.example.com`) && PathPrefix(`/api`)
      - traefik.http.routers.api.service=api@internal
      - traefik.http.routers.api.entrypoints=web

networks:
  traefikweb:
    external: true

Usage:

http://traefik.example.com -> will take you to dashboard

http://traefik.example.com/api/rawdata -> will take you to api

I have also removed port forwarding 8080:8080. So only way to access the api is through the url http://traefik.example.com/api/.. .

This is my first step towards dashboard and api routing. Next step is to secure it.

I've been poking at this for a bit and the following configuration works for me. This exposes the dashboard at http://traefik.internal/dashboard and the API at http://traefik.internal/api .


version: '3.7'
services:
  traefik:
    image: traefik:v2.9.6
    container_name: traefik
    hostname: traefik
    restart: always
    ports:
      - 80:80
      - 8080:8080
    command:
      - --api.insecure=true
      - --api.dashboard=true
      - --api.debug=true
      - --log.level=INFO
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --providers.docker.network=traefikweb
      - --entrypoints.web.address=:80
      - --accessLog.filePath=/dev/stderr
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - traefikweb
    labels:
      - traefik.enable=true

      - traefik.http.routers.api.rule=Host(`traefik.internal`) && PathPrefix(`/api`)
      - traefik.http.routers.api.service=api@internal
      - traefik.http.routers.api.entrypoints=web

      - traefik.http.routers.dashboard.rule=Host(`traefik.internal`) && PathPrefix(`/dashboard`)
      - traefik.http.routers.dashboard.service=dashboard@internal
      - traefik.http.routers.dashboard.entrypoints=web

      # configure stripprefix rule for the dashboard
      - traefik.http.routers.dashboard.middlewares=dashboard-stripprefix
      - traefik.http.middlewares.dashboard-stripprefix.stripprefix.prefixes=/dashboard
networks:
  traefikweb:
    external: true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM