Bug: custom error_page doesn't work for HTTP 413 (content too large)

Michael Nachbaur mike at nachbaur.com
Thu Jun 4 03:13:49 MSD 2009


After a few hours of digging through the nginx code, I think I've  
discovered the nature of the bug, but I still don't know how to fix it  
just yet.  I'm using the 3rd-party upload module to handle my uploads,  
which are then sent along to a fastcgi process.

The problem I'm having is I can't seem to set a custom error page for  
HTTP 413 errors.  If I issue a file upload to an nginx url and it  
exceeds the maximum size set in my configuration, I want the custom  
error page to show.  Instead I get the nginx default.

    error_page 413 /err/413.html

when I upload will give me something like this in my error log:

2009/06/03 23:08:06 [error] 19180#0: *163 client intended to send too  
large body: 995365 bytes, client: 192.168.98.223, server: localhost,  
request: "POST /attach HTTP/1.1", host: "localhost:10443", referrer: "https://localhost:10443/attach 
"
2009/06/03 23:08:06 [error] 19180#0: *163 client intended to send too  
large body: 995365 bytes, client: 192.168.98.223, server: localhost,  
request: "POST /attach HTTP/1.1", host: "localhost:10443", referrer: "https://localhost:10443/attach 
"


When I pointed the error page at an invalid location (error_page 413  
@bad_location) I got this instead:

2009/06/03 23:06:31 [error] 11885#0: *153 client intended to send too  
large body: 995365 bytes, client: 192.168.98.223, server: localhost,  
request: "POST /attach HTTP/1.1", host: "localhost:10443", referrer: "https://localhost:10443/attach 
"
2009/06/03 23:06:31 [error] 11885#0: *153 could not find named  
location "@bad_location", client: 192.168.98.223, server: localhost,  
request: "POST /attach HTTP/1.1", host: "localhost:10443", referrer: "https://localhost:10443/attach 
"

So what I think is happening is the initial request is made, which  
eventually throws a NGX_HTTP_REQUEST_ENTITY_TOO_LARGE error, resulting  
in the error page handler to run.  It tries cleaning up the request  
and resets it to an internal request for /err/413.html, but I think it  
isn't cleaning everything up well enough. So when the error page tries  
to load, it notices that the content length of the request is still  
too large, and throws an error as well.

Does anyone have any idea how to fix this, or would like to submit a  
patch?  I'm going to try my best to fix the code, and if I can I'll  
send a patch in to the mailing list.  But my C skills aren't that  
solid, and I'm unfamiliar with the nginx codebase.

Thank you, and I hope someone has a magic-bullet solution for this. :-)





More information about the nginx mailing list