ingress-nginx-helm/docs/user-guide/custom-errors.md

31 lines
1.8 KiB
Markdown
Raw Normal View History

2017-10-13 13:55:03 +00:00
# Custom errors
When the [`custom-http-errors`][cm-custom-http-errors] option is enabled, the Ingress controller configures NGINX so
that it passes several HTTP headers down to its `default-backend` in case of error:
2017-10-13 13:55:03 +00:00
| Header | Value |
| ---------------- | ------------------------------------------------ |
| `X-Code` | HTTP status code retuned by the request |
| `X-Format` | Value of the `Accept` header sent by the client |
| `X-Original-URI` | URI that caused the error |
| `X-Namespace` | Namespace where the backend Service is located |
| `X-Ingress-Name` | Name of the Ingress where the backend is defined |
| `X-Service-Name` | Name of the Service backing the backend |
| `X-Service-Port` | Port number of the Service backing the backend |
A custom error backend can use this information to return the best possible representation of an error page. For
example, if the value of the `Accept` header send by the client was `application/json`, a carefully crafted backend
could decide to return the error payload as a JSON document instead of HTML.
2017-10-13 13:55:03 +00:00
2018-04-29 06:17:29 +00:00
!!! Important
The custom backend is expected to return the correct HTTP status code instead of `200`. NGINX does not change
the response from the custom default backend.
2017-10-13 13:55:03 +00:00
An example of such custom backend is available inside the source repository at [images/custom-error-pages][img-custom-error-pages].
2017-10-13 13:55:03 +00:00
See also the [Custom errors][example-custom-errors] example.
2017-10-13 13:55:03 +00:00
[cm-custom-http-errors]: ./nginx-configuration/configmap.md#custom-http-errors
[img-custom-error-pages]: https://github.com/kubernetes/ingress-nginx/tree/master/images/custom-error-pages
[example-custom-errors]: ../examples/customization/custom-errors