Search code examples
nginxnginx-configcustom-error-pages

Nginx default error page is still showing


I added custom error page to Nginx by these lines:

error_page 400 /custom.html;
location = /custom.html {
  root /somewhere/html;
  internal;
}

location /test {
  return 400;
}

It returns my custom error page for test location; The problem is for some requests like when request header is too large, It still returns the default error page of Nginx.

<html>
  <head><title>400 Request Header Or Cookie Too Large</title></head>
  <body>
  <center><h1>400 Bad Request</h1></center>
  <center>Request Header Or Cookie Too Large</center>
  <hr><center>nginx</center>
  </body>
</html>


Solution

  • Apparently this specific error uses code 494 internally.

    You can try with

    error_page 494 =400 /custom.html
    

    I found that on the nginx mailing list:

    Try handling 494 errors instead. It's a custom code used to report "Request Header Too Large" errors, translated to 400 just before returning to client. It was introduced in nginx 0.9.4 to make it possible to define a custom error page for these particular errors separately from generic 400 errors.

    https://mailman.nginx.org/pipermail/nginx/2018-June/056342.html