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

Igor Sysoev is at rambler-co.ru
Mon Aug 31 20:22:54 MSD 2009


On Mon, Aug 31, 2009 at 03:38:44PM +0000, Peter Vandenberk wrote:

> pvdb <nginx-forum at ...> writes:
> > I am dealing with the same requirement (implement a custom 
> > 413 nginx error page) and am banging my head against the 
> > wall for the same reason that Mike describes in his original post.
> > 
> > Posted at Nginx Forum: 
> > http://forum.nginx.org/read.php?2,2620,5422#msg-5422
> 
> It appears that the cross-posting between the two mailing lists 
> has truncated my original post... 
> 
> Here's a bit more context from Mike's original post:
> 
> > 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: ...
> 
> Basically I'm having the same issue, and no matter how many different
> variations of my nginx.conf I try, I can not get it to serve my custom 
> 413.html error page, but *always* serves the default nginx 413 one.
> 
> Here's the relevant snippet from my nging.conf file:
> 
>         error_page  413              /413.html;
>         location = /413.html {
>             root   /usr/local/nginx/html;
>         }
> 
> Any ideas?  Many thanks in advance,

The attached patch should fix the bug.

However, browsers usually show the 413 error page only after they have sent
a whole request body. Therefore on slow connection and with large body
browsers will show some network error or "this page cannot be displayed" page.


-- 
Igor Sysoev
http://sysoev.ru/en/
-------------- next part --------------
Index: src/http/ngx_http_core_module.c
===================================================================
--- src/http/ngx_http_core_module.c	(revision 2391)
+++ src/http/ngx_http_core_module.c	(working copy)
@@ -917,6 +917,7 @@
                       "client intended to send too large body: %O bytes",
                       r->headers_in.content_length_n);
 
+        (void) ngx_http_discard_request_body(r);
         ngx_http_finalize_request(r, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE);
         return NGX_OK;
     }


More information about the nginx mailing list