ErrorPage

说错了从来没有像现在这样容易

ErrorPages

根据配置的HTTP状态代码范围,ErrorPage中间件返回一个自定义页面来代替默认页面.

Important

错误页面本身不是由Traefik托管的.

Configuration Examples

# Dynamic Custom Error Page for 5XX Status Code
labels:
  - "traefik.http.middlewares.test-errorpage.errors.status=500-599"
  - "traefik.http.middlewares.test-errorpage.errors.service=serviceError"
  - "traefik.http.middlewares.test-errorpage.errors.query=/{status}.html"
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: test-errorpage
spec:
  errors:
    status:
      - 500-599
    query: /{status}.html
    service:
      name: whoami
      port: 80
"labels": {
  "traefik.http.middlewares.test-errorpage.errors.status": "500-599",
  "traefik.http.middlewares.test-errorpage.errors.service": "serviceError",
  "traefik.http.middlewares.test-errorpage.errors.query": "/{status}.html"
}
# Dynamic Custom Error Page for 5XX Status Code
labels:
  - "traefik.http.middlewares.test-errorpage.errors.status=500-599"
  - "traefik.http.middlewares.test-errorpage.errors.service=serviceError"
  - "traefik.http.middlewares.test-errorpage.errors.query=/{status}.html"
# Custom Error Page for 5XX
[http.middlewares]
  [http.middlewares.test-errorpage.errors]
    status = ["500-599"]
    service = "serviceError"
    query = "/{status}.html"

[http.services]
  # ... definition of error-handler-service and my-service
# Custom Error Page for 5XX
http:
  middlewares:
    test-errorpage:
      errors:
        status:
          - "500-599"
        service: serviceError
        query: "/{status}.html"

[http.services]
  # ... definition of error-handler-service and my-service

在此示例中,错误页面URL基于状态码( query=/{status}.html ).

Configuration Options

status

触发错误页面的status .

状态代码范围包括在内( 500-599将触发,其中包括500599之间的每个代码,包括500599之间的代码).

您可以使用500-599类的语法来定义状态码(例如500或范围.

service

将为新的请求的错误页面提供服务的服务.

在kubernetes中,您需要引用kubernetes服务而不是traefik服务.

query

错误页面的URL(由service托管). 您可以在查询中使用{status} ,它将由接收到的状态代码代替.