Update documentation for custom error pages (#2630)
* Update documentation for custom error pages * custom-error-pages: Fix path to error pages Bump version to 0.2
This commit is contained in:
parent
306910d956
commit
55679aa268
9 changed files with 1945 additions and 148 deletions
|
|
@ -1,19 +1,30 @@
|
|||
# Custom errors
|
||||
|
||||
In case of an error in a request the body of the response is obtained from the `default backend`.
|
||||
Each request to the default backend includes two headers:
|
||||
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:
|
||||
|
||||
- `X-Code` indicates the HTTP code to be returned to the client.
|
||||
- `X-Format` the value of the `Accept` header.
|
||||
| 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.
|
||||
|
||||
!!! Important
|
||||
The custom backend must return the correct HTTP status code to be returned. NGINX does not change the response from the custom default backend.
|
||||
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.
|
||||
|
||||
Using these two headers it's possible to use a custom backend service like [this one](https://github.com/kubernetes/ingress-nginx/tree/master/images/custom-error-pages) that inspects each request and returns a custom error page with the format expected by the client. Please check the example [custom-errors](https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/customization/custom-errors).
|
||||
An example of such custom backend is available inside the source repository at [images/custom-error-pages][img-custom-error-pages].
|
||||
|
||||
NGINX sends additional headers that can be used to build custom response:
|
||||
See also the [Custom errors][example-custom-errors] example.
|
||||
|
||||
- X-Original-URI
|
||||
- X-Namespace
|
||||
- X-Ingress-Name
|
||||
- X-Service-Name
|
||||
[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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue