Welcome! Log In Create A New Profile

Advanced

large_client_header_buffers: Custom error pages are not working

Posted by prajos 
Hi there,
I'm using nginx nginx version 1.12.0 as a reverse proxy to my application
servers.
I allow certain top level checks like header size and count to be done at
nginx level.

The server block looks like the following:

server {
listen 443 ssl default_server;
...
large_client_header_buffers 32 512;
...
location / {
...
}

error_page 400 /400.json;
location = /400.json {
root /etc/nginx/errors-files/;
allow all;
internal;
}

}

Then I start testing the nginx with curl and adding a header of size 600
bytes.
nginx promptly stops the request and dumps a default error page instead of
my custom error page.

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


How can I get a CUSTOM ERROR page for this situation working instead of the
default page.
Thanks
Cheers
prajos

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,280035,280035#msg-280035

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Hello!

On Tue, Jun 05, 2018 at 05:34:10AM -0400, prajos wrote:

> Hi there,
> I'm using nginx nginx version 1.12.0 as a reverse proxy to my application
> servers.
> I allow certain top level checks like header size and count to be done at
> nginx level.
>
> The server block looks like the following:
>
> server {
> listen 443 ssl default_server;
> ..
> large_client_header_buffers 32 512;
> ..
> location / {
> ...
> }
>
> error_page 400 /400.json;
> location = /400.json {
> root /etc/nginx/errors-files/;
> allow all;
> internal;
> }
>
> }
>
> Then I start testing the nginx with curl and adding a header of size 600
> bytes.
> nginx promptly stops the request and dumps a default error page instead of
> my custom error page.
>
> <html>
> <head><title>400 Request Header Or Cookie Too Large</title></head>
> <body bgcolor="white">
> <center><h1>400 Bad Request</h1></center>
> <center>Request Header Or Cookie Too Large</center>
> <hr><center>nginx</center>
> </body>
> </html>
>
>
> How can I get a CUSTOM ERROR page for this situation working instead of the
> default page.

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.

(It looks like it's not documented anywhere but in CHANGES though.
This needs to be fixed.)

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Thanks Maxim Dounin,
The trick worked.
I did something like the following:


server {
large_client_header_buffers 12 64;
....
error_page 494 =400 /400.json;
error_page 400 /400.json;

location = /400.json {
add_header Funky-Header1 'Funky Value' always;
root /etc/nginx/error-files/;
allow all;
internal;
}
}
& now I'm able to get my custom message and Header.

Cheers

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,280035,280044#msg-280044

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login