🐦‍⬛Documentation

Error Pages

Configure custom error pages in Traefik

To setup error pages (404, 503 etc) on Traefik, a few changes need to be made.

Traefik.yml

To prevent the site from hanging, add the following lines to serversTransport in traefik.yml. This ensures the client recieves the error status page after 1 second.

serversTransport:
  insecureSkipVerify: true
  forwardingTimeouts:
    dialTimeout: 1s

Default dial timeout is 30 seconds - This can be too long of a wait for the client before forwarding error.

Config.yml

http:
## Routers ##
  routers:
    MyWebPage:
      entryPoints:
        - https
      rule: "Host(`exmaple.com`)"
      service: MyWebPage
      middlewares:
        - "custom-errors" # Make sure to remember adding the middleware
      # - "securityHeaders"

## Services ##
  services:
    eror-status:
      loadBalancer:
        servers:
          - url: http://error-status:80 # Point to webserver with errors

 ## MIDDLEWARES ##
  middlewares:
    custom-errors:
      errors:
        status:
          - "400-599"
        service: error-service
        query: "/errors/{status}.html" # In the errors folder find status

In this example, we are using an existing webserver to house the html files. The middleware will catch all error codes between 400 and 599.

Important error pages to create:

  1. 404.html
  2. 503.html
  3. 504.html

On this page