Custom Errors
This example demonstrates how to use a custom backend to render custom error pages.
Customized default backend
First, create the custom default-backend
. It will be used by the Ingress controller later on.
This should have created a Deployment and a Service with the name nginx-errors
.
Ingress controller configuration
If you do not already have an instance of the nginx Ingress controller running, deploy it according to the deployment guide, then follow these steps:
Edit the
nginx-ingress-controller
Deployment and set the value of the--default-backend
flag to the name of the newly created error backend.Edit the
nginx-configuration
ConfigMap and create the keycustom-http-errors
with a value of404,503
.Take note of the IP address assigned to the nginx Ingress controller Service.
!!! Note The ingress-nginx
Service is of type ClusterIP
in this example. This may vary depending on your environment. Make sure you can use the Service to reach nginx before proceeding with the rest of this example.
Testing error pages
Let us send a couple of HTTP requests using cURL and validate everything is working as expected.
A request to the default backend returns a 404 error with a custom message:
A request with a custom Accept
header returns the corresponding document type (JSON):
To go further with this example, feel free to deploy your own applications and Ingress objects, and validate that the responses are still in the correct format when a backend returns 503 (eg. if you scale a Deployment down to 0 replica).
Last updated