Back to Ingress Nginx

Custom errors

docs/user-guide/custom-errors.md

latest2.0 KB
Original Source

Custom errors

When the 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:

HeaderValue
X-CodeHTTP status code returned by the request
X-FormatValue of the Accept header sent by the client
X-Original-URIURI that caused the error
X-NamespaceNamespace where the backend Service is located
X-Ingress-NameName of the Ingress where the backend is defined
X-Service-NameName of the Service backing the backend
X-Service-PortPort number of the Service backing the backend
X-Request-IDUnique ID that identifies the request - same as for backend service

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 is expected to return the correct HTTP status code instead of 200. NGINX does not change the response from the custom default backend.

An example of such custom backend is available inside the source repository at images/custom-error-pages.

See also the Custom errors example.