#2408 closed defect (duplicate)

413 error_page directive in server or location context returns default 413 error page when using HTTP/2

Reported by: Seb Owned by:
Priority: minor Milestone:
Component: nginx-module Version: 1.23.x
Keywords: http2 Cc:
uname -a: Linux 5bc5c52e0a0d 5.14.0-1054-oem #61-Ubuntu SMP Fri Oct 14 13:05:50 UTC 2022 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.23.2
built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
built with OpenSSL 1.1.1n 15 Mar 2022
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -ffile-prefix-map=/data/builder/debuild/nginx-1.23.2/debian/debuild-base/nginx-1.23.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'


I think this is a bug, but I may be misunderstanding something.

If the error_page directive is set to a relative URI inside a server or location block the custom error page is not returned to HTTP/2 requests (the default Nginx one is). However requests using HTTP/1.1 work fine and receive the custom error page.

Example config:

server {
    listen       80;
    listen       443 ssl http2;
    listen  [::]:80;
    server_name  localhost;

    ssl_certificate /etc/nginx/ssl/nginx.crt;
    ssl_certificate_key /etc/nginx/ssl/nginx.key;

    error_page 413 /413/;

    location / {
        client_max_body_size 20m;

From the above example: is never requested when POSTing a >20M payload using HTTP/2 to Nginx. The default Nginx 413 error page is returned.

However making the same request using HTTP/1.1 results in a call to the upstream and this gets returned to the original request.

Change History (2)

comment:1 by Maxim Dounin, 21 months ago

Keywords: http2 added

Thanks for reporting this, it indeed looks like a bug in the HTTP/2.0 code. I'll take a look how to fix it properly.

Note though that the configuration with 413 error being redirected to a general proxied location is unsafe, since nginx will pass the request headers, notably Content-Length, but there will be no request body. Usual approach would be to either use a static file instead, or configure a special location for proxying such errors, with something like proxy_set_header Content-Length ""; proxy_pass_request_body off;.

comment:2 by Maxim Dounin, 12 months ago

Resolution: duplicate
Status: newclosed

See #1152, which turns out to be the same issue.

Note: See TracTickets for help on using tickets.