2022-04-15 13:44:08 +00:00
---
2022-05-10 09:00:09 +00:00
title: "Traefik Errors Documentation"
description: "In Traefik Proxy, the Errors middleware returns custom pages according to configured ranges of HTTP Status codes. Read the technical documentation."
2022-04-15 13:44:08 +00:00
---
2022-05-10 09:00:09 +00:00
# Errors
2019-02-26 13:50:07 +00:00
It Has Never Been Easier to Say That Something Went Wrong
{: .subtitle }
2022-05-10 09:00:09 +00:00
![Errors ](../../assets/img/middleware/errorpages.png )
2019-02-26 13:50:07 +00:00
2022-05-10 09:00:09 +00:00
The Errors middleware returns a custom page in lieu of the default, according to configured ranges of HTTP Status codes.
2019-02-26 13:50:07 +00:00
!!! important
2021-09-27 15:40:13 +00:00
2019-02-26 13:50:07 +00:00
The error page itself is _not_ hosted by Traefik.
## Configuration Examples
2023-05-10 13:28:05 +00:00
```yaml tab="Docker & Swarm"
2019-03-29 11:34:05 +00:00
# Dynamic Custom Error Page for 5XX Status Code
labels:
2023-11-17 15:30:06 +00:00
- "traefik.http.middlewares.test-errors.errors.status=500,501,503,505-599"
2022-05-10 09:00:09 +00:00
- "traefik.http.middlewares.test-errors.errors.service=serviceError"
- "traefik.http.middlewares.test-errors.errors.query=/{status}.html"
2019-03-29 11:34:05 +00:00
```
2019-04-03 12:32:04 +00:00
```yaml tab="Kubernetes"
2023-03-20 14:38:08 +00:00
apiVersion: traefik.io/v1alpha1
2019-04-03 12:32:04 +00:00
kind: Middleware
metadata:
2022-05-10 09:00:09 +00:00
name: test-errors
2019-04-03 12:32:04 +00:00
spec:
errors:
status:
2023-11-17 15:30:06 +00:00
- "500"
- "501"
- "503"
- "505-599"
2019-04-03 12:32:04 +00:00
query: /{status}.html
2019-09-10 15:24:03 +00:00
service:
name: whoami
port: 80
2019-04-03 12:32:04 +00:00
```
2019-10-15 15:34:08 +00:00
```yaml tab="Consul Catalog"
2023-11-17 15:30:06 +00:00
# Dynamic Custom Error Page for 5XX Status Code excluding 502 and 504
- "traefik.http.middlewares.test-errors.errors.status=500,501,503,505-599"
2022-05-10 09:00:09 +00:00
- "traefik.http.middlewares.test-errors.errors.service=serviceError"
- "traefik.http.middlewares.test-errors.errors.query=/{status}.html"
2019-10-15 15:34:08 +00:00
```
2019-07-22 07:58:04 +00:00
```yaml tab="File (YAML)"
2023-11-17 15:30:06 +00:00
# Dynamic Custom Error Page for 5XX Status Code excluding 502 and 504
2019-07-22 07:58:04 +00:00
http:
middlewares:
2022-05-10 09:00:09 +00:00
test-errors:
2019-07-22 07:58:04 +00:00
errors:
status:
2023-11-17 15:30:06 +00:00
- "500"
- "501"
- "503"
- "505-599"
2019-07-22 07:58:04 +00:00
service: serviceError
query: "/{status}.html"
2021-06-18 22:08:08 +00:00
services:
# ... definition of error-handler-service and my-service
```
```toml tab="File (TOML)"
2023-11-17 15:30:06 +00:00
# Dynamic Custom Error Page for 5XX Status Code excluding 502 and 504
2021-06-18 22:08:08 +00:00
[http.middlewares]
2022-05-10 09:00:09 +00:00
[http.middlewares.test-errors.errors]
2023-11-17 15:30:06 +00:00
status = ["500","501","503","505-599"]
2021-06-18 22:08:08 +00:00
service = "serviceError"
query = "/{status}.html"
2019-07-22 07:58:04 +00:00
[http.services]
# ... definition of error-handler-service and my-service
```
2021-02-11 13:34:04 +00:00
!!! note ""
2019-09-03 16:02:05 +00:00
In this example, the error page URL is based on the status code (`query=/{status}.html`).
2019-02-26 13:50:07 +00:00
## Configuration Options
2019-04-03 12:32:04 +00:00
### `status`
2019-02-26 13:50:07 +00:00
2021-02-11 13:34:04 +00:00
The `status` option defines which status or range of statuses should result in an error page.
2019-02-26 13:50:07 +00:00
2023-11-17 15:30:06 +00:00
The status code ranges are inclusive (`505-599` will trigger with every code between `505` and `599` , `505` and `599` included).
2019-02-26 13:50:07 +00:00
2021-02-11 13:34:04 +00:00
!!! note ""
2021-06-08 17:02:05 +00:00
You can define either a status code as a number (`500`),
as multiple comma-separated numbers (`500,502`),
2023-11-17 15:30:06 +00:00
as ranges by separating two codes with a dash (`505-599`),
or a combination of the two (`404,418,505-599`).
The comma-separated syntax is only available for label-based providers.
The examples above demonstrate which syntax is appropriate for each provider.
2019-02-26 13:50:07 +00:00
2019-04-03 12:32:04 +00:00
### `service`
2019-02-26 13:50:07 +00:00
The service that will serve the new requested error page.
2021-02-11 13:34:04 +00:00
!!! note ""
In Kubernetes, you need to reference a Kubernetes Service instead of a Traefik service.
2019-09-10 15:24:03 +00:00
2021-09-27 15:40:13 +00:00
!!! info "Host Header"
By default, the client `Host` header value is forwarded to the configured error [service ](#service ).
2022-05-10 09:00:09 +00:00
To forward the `Host` value corresponding to the configured error service URL, the [passHostHeader ](../../../routing/services/#pass-host-header ) option must be set to `false` .
2021-09-27 15:40:13 +00:00
2019-04-03 12:32:04 +00:00
### `query`
2019-02-26 13:50:07 +00:00
2022-05-10 09:00:09 +00:00
The URL for the error page (hosted by [`service` ](#service ))).
There are multiple variables that can be placed in the `query` option to insert values in the URL.
The table below lists all the available variables and their associated values.
| Variable | Value |
|------------|--------------------------------------------------------------------|
| `{status}` | The response status code. |
| `{url}` | The [escaped ](https://pkg.go.dev/net/url#QueryEscape ) request URL. |