<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
I'm using nginx/1.20.1 under CentOS Linux release 7.9.2009 (Core)
and I cannot get a custom error page to show when the
client_max_body_size limit has been exceeded. The browser will only
return the default nginx error page.<br>
<br>
I see a number of posts mentioning how there was a bug in earlier
versions of nginx, but this appears to be have been fixed a long
time ago.<br>
<br>
In my code, I have the following:<br>
<br>
<font face="monospace">
<blockquote type="cite"><font face="monospace">error_page 404 =404
/404_status_code.htm;<br>
error_page 403 =404 /404_status_code.htm;<br>
<br>
location /404_status_code.htm {<br>
internal;<br>
root /path/to/my/custom/errors/;<br>
add_header X-Original-URL
"$scheme://$http_host$request_uri" always;<br>
}</font></blockquote>
</font><br>
This works perfectly fine. When either a 403 or 404 error is
generated, nginx returns my custom error page.<br>
<br>
However, if I change the code to:<br>
<br>
<font face="monospace">
<blockquote type="cite"><font face="monospace">error_page 404 =404
/404_status_code.htm;<br>
error_page 403 =404 /404_status_code.htm;<br>
error_page 413 =413 /413_request_too_large.htm;<br>
<br>
location /404_status_code.htm {<br>
internal;<br>
root /path/to/my/custom/errors/;<br>
add_header X-Original-URL
"$scheme://$http_host$request_uri" always;<br>
}<br>
<br>
location /413_request_too_large.htm {<br>
internal;<br>
root /path/to/my/custom/errors/;<br>
add_header X-Original-URL
"$scheme://$http_host$request_uri" always;<br>
}</font></blockquote>
</font><br>
When I try to upload a file larger than my client_max_body_size
setting, I still get the default error page. I've tried a lot of
different variations of the code, but nothing seems to work.<br>
<br>
I've tried:<br>
<br>
<font face="monospace">
<blockquote type="cite"><font face="monospace">error_page 413
/413_request_too_large.htm;<br>
location /413_request_too_large.htm {<br>
internal;<br>
root /path/to/my/custom/errors/;<br>
add_header X-Original-URL
"$scheme://$http_host$request_uri" always;<br>
}</font></blockquote>
</font><br>
Using an handler instead:<br>
<br>
<font face="monospace">
<blockquote type="cite"><font face="monospace">error_page 413
@413_request_too_large<br>
location @413_request_too_large {<br>
internal;<br>
root /path/to/my/custom/errors/;<br>
add_header X-Original-URL
"$scheme://$http_host$request_uri" always;<br>
}</font></blockquote>
</font><br>
And every variation I can think of, but nothing seems to work.<br>
<br>
Is there something special that needs to be done to implement a
custom error page for a 413 status code? Or is there perhaps a
regression that broke this from working?<br>
<br>
<font face="Helvetica, Arial, sans-serif">-Dan</font><br>
<pre class="moz-signature" cols="72">--
Dan G. Switzer, II
Giva, Inc.
Email: <a class="moz-txt-link-abbreviated" href="mailto:dan.switzer@givainc.com">dan.switzer@givainc.com</a>
Web Site: <a class="moz-txt-link-freetext" href="http://www.givainc.com">http://www.givainc.com</a>
See Our Customer Successes
<a class="moz-txt-link-freetext" href="http://www.givainc.com/customers-casestudies.htm">http://www.givainc.com/customers-casestudies.htm</a>
</pre>
</body>
</html>