Welcome! Log In Create A New Profile

Advanced

Custom 413 error pages when client_max_body_size exceeded

Dan G. Switzer, II
October 20, 2022 09:06AM
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.

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.

In my code, I have the following:

> error_page 404 =404 /404_status_code.htm;
> error_page 403 =404 /404_status_code.htm;
>
> location /404_status_code.htm {
>     internal;
>     root /path/to/my/custom/errors/;
>     add_header X-Original-URL "$scheme://$http_host$request_uri" always;
> }

This works perfectly fine. When either a 403 or 404 error is generated,
nginx returns my custom error page.

However, if I change the code to:

> error_page 404 =404 /404_status_code.htm;
> error_page 403 =404 /404_status_code.htm;
> error_page 413 =413 /413_request_too_large.htm;
>
> location /404_status_code.htm {
>     internal;
>     root /path/to/my/custom/errors/;
>     add_header X-Original-URL "$scheme://$http_host$request_uri" always;
> }
>
> location /413_request_too_large.htm {
>     internal;
>     root /path/to/my/custom/errors/;
>     add_header X-Original-URL "$scheme://$http_host$request_uri" always;
> }

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.

I've tried:

> error_page 413 /413_request_too_large.htm;
> location /413_request_too_large.htm {
>     internal;
>     root /path/to/my/custom/errors/;
>     add_header X-Original-URL "$scheme://$http_host$request_uri" always;
> }

Using an handler instead:

> error_page 413 @413_request_too_large
> location @413_request_too_large {
>     internal;
>     root /path/to/my/custom/errors/;
>     add_header X-Original-URL "$scheme://$http_host$request_uri" always;
> }

And every variation I can think of, but nothing seems to work.

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?

-Dan

--
Dan G. Switzer, II
Giva, Inc.
Email:dan.switzer@givainc.com
Web Site:http://www.givainc.com

See Our Customer Successes
http://www.givainc.com/customers-casestudies.htm
_______________________________________________
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-leave@nginx.org
Subject Author Posted

Custom 413 error pages when client_max_body_size exceeded

Dan G. Switzer, II October 20, 2022 09:06AM

Re: Custom 413 error pages when client_max_body_size exceeded

Sergey A. Osokin October 20, 2022 11:06AM

Re: Custom 413 error pages when client_max_body_size exceeded

Dan G. Switzer, II October 20, 2022 02:02PM

Re: Custom 413 error pages when client_max_body_size exceeded

Sergey A. Osokin October 20, 2022 02:46PM

Re: Custom 413 error pages when client_max_body_size exceeded

Frank Swasey October 20, 2022 04:24PM

Re: Custom 413 error pages when client_max_body_size exceeded

Dan G. Switzer, II October 20, 2022 04:26PM

Re: Custom 413 error pages when client_max_body_size exceeded

Sergey A. Osokin October 20, 2022 07:50PM

Re: Custom 413 error pages when client_max_body_size exceeded

Dan G. Switzer, II October 21, 2022 07:16AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 191
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready