kubernetes-ingress icon indicating copy to clipboard operation
kubernetes-ingress copied to clipboard

Custom error page for 404, 503 errors

Open meektechie opened this issue 2 years ago • 12 comments

Is your feature request related to a problem? Please describe.

With reference to the previous issue https://github.com/nginxinc/kubernetes-ingress/issues/752, we are trying to apply a custom error page across the services using nginx ingress. Describe the solution you'd like

We want a solution like the community version is providing through the defaultbackend container. https://kubernetes.github.io/ingress-nginx/examples/customization/custom-errors/ Describe alternatives you've considered No, We cant change it as it is already rolled out. Additional context

meektechie avatar Nov 08 '23 13:11 meektechie

Hi @meektechie thanks for reporting!

Be sure to check out the docs and the Contributing Guidelines while you wait for a human to take a look at this :slightly_smiling_face:

Cheers!

github-actions[bot] avatar Nov 08 '23 13:11 github-actions[bot]

@meektechie this is currently something we address through the project custom resources today: https://docs.nginx.com/nginx-ingress-controller/configuration/virtualserver-and-virtualserverroute-resources/#errorpage

However, that capability is built to handle API Gateway style behavior that is commonly custom per hostname or path.

Since you mention the default backend behavior. Are you looking for a catch-all when no hostnames or paths match? Rather than the default NGINX behavior of no response when there is no match, you are looking for programming a response. Is that correct?

And I am also making the assumption that your organization is committed to the Ingress resource exclusively. Is that also correct?

brianehlert avatar Nov 08 '23 15:11 brianehlert

Yes You are right, We are looking to catch all when no hostnaes or paths match. We just want to add a custom error page/html file instead of the default 404 response. That response will be very simple, something like "Not Found" since the response code is already captured under response header.

meektechie avatar Nov 08 '23 16:11 meektechie

Have you discovered: https://docs.nginx.com/nginx-ingress-controller/configuration/global-configuration/configmap-resource/#:~:text=False-,default%2Dserver%2Dreturn,-Configures%20the%20return To see how close this is to what you are looking for?

brianehlert avatar Nov 09 '23 17:11 brianehlert

@meektechie you can use the item @brianehlert mentioned to redirect any unknown hostname/resources. Here is a small example:

apiVersion: v1
data:
  default-server-return: 302 https://nginx.org
kind: ConfigMap
metadata:
  name: nginx-config
  namespace: nginx-ingress

Basically, any unmatched resources will be sent a 302 and redirected to https://nginx.org HTH

jasonwilliams14 avatar Nov 09 '23 17:11 jasonwilliams14

Thanks for sharing this, I already went through this. I need to apply a custom response for the 404 page but the custom response always goes to 302. Screenshot 2023-11-09 at 10 58 32 PM

meektechie avatar Nov 09 '23 17:11 meektechie

With this page, i want to cusomize.

400 The plain HTTP request was sent to HTTPS port

400 Bad Request

The plain HTTP request was sent to HTTPS port

nginx

meektechie avatar Nov 09 '23 17:11 meektechie

Idea: Use another URL that is also hosted under a different path as the redirect and back it with a very small web server service and your page. http://foo.com/404.html Then it can be HTTP and get picked up by any HTTP to HTTPS behavior that is set for the hostname.

Since the 30x happens at the client side anyway it is not a forward (aka proxy_pass).

brianehlert avatar Nov 09 '23 22:11 brianehlert

Hi @meektechie has your issue been resolved? Are you happy to close the issue?

haywoodsh avatar Nov 20 '23 16:11 haywoodsh

Nope, it isn't working

meektechie avatar Nov 27 '23 11:11 meektechie

highlighting this as still not resolved

vepatel avatar Jan 15 '24 16:01 vepatel

Hi @meektechie Are you using an Ingress resource or a VirtualServer/VirtualServerRoute resource?

If you happen to be using VirtualServer & VirtualServerRoutes , we allow error pages to be customised using our ErrorPage feature.

shaun-nx avatar Feb 12 '24 16:02 shaun-nx