From b8fe9eb031c9b3a195c32f6a2a160d406f8cb1b5 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Thu, 28 Sep 2017 19:41:08 -0300 Subject: [PATCH] Improve custom error pages doc --- controllers/nginx/README.md | 19 +++++++++++++++---- .../custom-errors/nginx/README.md | 4 +--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/controllers/nginx/README.md b/controllers/nginx/README.md index fea53c8148..1ad2c1027e 100644 --- a/controllers/nginx/README.md +++ b/controllers/nginx/README.md @@ -381,11 +381,22 @@ Please check the [proxy-protocol](examples/proxy-protocol/) example ### 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: -- `X-Code` indicates the HTTP code -- `X-Format` the value of the `Accept` header +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: -Using this two headers is possible to use a custom backend service like [this one](https://github.com/aledbf/contrib/tree/nginx-debug-server/Ingress/images/nginx-error-server) that inspect each request and returns a custom error page with the format expected by the client. Please check the example [custom-errors](examples/custom-errors/README.md) +- `X-Code` indicates the HTTP code to be returned to the client. +- `X-Format` the value of the `Accept` header. + +**Important:** the custom backend must return the correct HTTP status code to be returned. NGINX do not changes the reponse from the custom default backend. + +Using this two headers is possible to use a custom backend service like [this one](https://github.com/kubernetes/ingress/tree/master/examples/customization/custom-errors/nginx) that inspect each request and returns a custom error page with the format expected by the client. Please check the example [custom-errors](examples/customization/custom-errors/nginx/README.md) + +NGINX sends aditional headers that can be used to build custom response: + +- X-Original-URI +- X-Namespace +- X-Ingress-Name +- X-Service-Name ### NGINX status page diff --git a/examples/customization/custom-errors/nginx/README.md b/examples/customization/custom-errors/nginx/README.md index 2f79388d5f..c37240afb8 100644 --- a/examples/customization/custom-errors/nginx/README.md +++ b/examples/customization/custom-errors/nginx/README.md @@ -1,4 +1,4 @@ -This example shows how is possible to use a custom backend to render custom error pages. The code of this example is located here [nginx-debug-server](https://github.com/aledbf/contrib/tree/nginx-debug-server) +This example shows how is possible to use a custom backend to render custom error pages. The code of this example is located here [custom-error-pages](https://github.com/kubernetes/ingress/tree/master/examples/customization/custom-errors/nginx) The idea is to use the headers `X-Code` and `X-Format` that NGINX pass to the backend in case of an error to find out the best existent representation of the response to be returned. i.e. if the request contains an `Accept` header of type `json` the error should be in that format and not in `html` (the default in NGINX). @@ -78,5 +78,3 @@ $ curl -v http://172.17.4.99/ -H 'Accept: application/json' * Connection #0 to host 172.17.4.99 left intact ``` - -By default the Ingress controller provides support for `html`, `json` and `XML`.