The Dashboard

看看发生了什么

仪表板是显示您Traefik当前正在处理的活动路线的中心位置.

Dashboard - Providers
行动仪表板

仪表板与API位于同一位置,但默认情况下位于/dashboard/路径上.

结尾的斜线//dashboard/强制性

有两种方法可以配置和访问仪表板:

还有一个将路径/重定向到/dashboard/的路径,但是由于该属性必定会发生变化,因此不应依赖于该属性,并且无论如何它可能会使路由规则混乱.

Secure Mode

这是推荐的方法.

首先在静态配置上使用Traefik API中的以下选项启用仪表板:

[api]
  # Dashboard
  #
  # Optional
  # Default: true
  #
  dashboard = true
api:
  # Dashboard
  #
  # Optional
  # Default: true
  #
  dashboard: true
# Dashboard
#
# Optional
# Default: true
#
--api.dashboard=true

然后在Traefik本身上定义路由配置,并在动态配置中将路由器附加到服务[email protected] ,以允许定义:

仪表板动态配置示例
# Dynamic Configuration
labels:
  - "traefik.http.routers.api.rule=Host(`traefik.domain.com`)"
  - "[email protected]"
  - "traefik.http.routers.api.middlewares=auth"
  - "traefik.http.middlewares.auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
# Dynamic Configuration
deploy:
  labels:
    - "traefik.http.routers.api.rule=Host(`traefik.domain.com`)"
    - "[email protected]"
    - "traefik.http.routers.api.middlewares=auth"
    - "traefik.http.middlewares.auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
    # Dummy service for Swarm port detection. The port can be any valid integer value.
    - "traefik.http.services.dummy-svc.loadbalancer.server.port=9999"
"labels": {
  "traefik.http.routers.api.rule": "Host(`traefik.domain.com`)",
  "traefik.http.routers.api.service": "[email protected]",
  "traefik.http.routers.api.middlewares": "auth",
  "traefik.http.middlewares.auth.basicauth.users": "test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
}
# Dynamic Configuration
labels:
  - "traefik.http.routers.api.rule=Host(`traefik.domain.com`)"
  - "[email protected]"
  - "traefik.http.routers.api.middlewares=auth"
  - "traefik.http.middlewares.auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
# Dynamic Configuration
[http.routers.my-api]
  rule = "Host(`traefik.domain.com`)"
  service = "[email protected]"
  middlewares = ["auth"]

[http.middlewares.auth.basicAuth]
  users = [
    "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/",
    "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
  ]
# Dynamic Configuration
http:
  routers:
    api:
      rule: Host(`traefik.domain.com`)
      service: [email protected]
      middlewares:
        - auth
  middlewares:
    auth:
      basicAuth:
        users:
          - "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"
          - "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"

Dashboard Router Rule

api.dashboard选项文档中所强调的那样, api.dashboard定义的路由器规则必须与路径前缀/api/dashboard匹配.

我们建议使用"基于主机的规则"作为Host(`traefik.domain.com`)来匹配主机域上的所有内容,或确保定义的规则同时捕获两个前缀:

# The dashboard can be accessed on http://traefik.domain.com/dashboard/
rule = "Host(`traefik.domain.com`)"
# The dashboard can be accessed on http://domain.com/dashboard/ or http://traefik.domain.com/dashboard/
rule = "PathPrefix(`/api`) || PathPrefix(`/dashboard`)"
# The dashboard can be accessed on http://traefik.domain.com/dashboard/
rule = "Host(`traefik.domain.com`) && (PathPrefix(`/api`) || PathPrefix(`/dashboard`))"

Insecure Mode

不建议使用此模式,因为它不允许使用安全功能.

要启用"不安全模式",请使用Traefik的API中的以下选项:

[api]
  dashboard = true
  insecure = true
api:
  dashboard: true
  insecure: true
--api.dashboard=true --api.insecure=true

现在,您可以在以下URL的Traefik实例的端口8080上访问仪表板: http://<Traefik IP>:8080/dashboard/ (必须使用斜杠).