Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

nginx 413 Request Entity Too Large on file upload

Error413 Request Entity Too Large

Short answer

nginx refuses any request body bigger than client_max_body_size, which defaults to 1 MB, and answers 413. Raise the value in the http, server or location block that handles the upload, test the config, and reload. If the setting seems ignored, the change was not loaded or a syntax error stopped the reload.

  • Applies to nginx 1.26, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the error log for the exact size nginx saw and the location it matched, then print the limit that is currently loaded.

    sudo grep "too large body" /var/log/nginx/error.log | tail -n 3
    sudo nginx -T 2>/dev/null | grep client_max_body_size
  2. 2Match what you see, then jump to its fix

    1. 1client intended to send too large body: 1048576 bytes, and nginx -T prints no client_max_body_sizeThe default limit of 1 MB is still in forceFix
    2. 2The error log still shows the old size after you edited the fileThe new value was never loadedFix

What does the error look like?

  • 413 Request Entity Too Large
  • client intended to send too large body: 1048576 bytes

Cause 1 of 2

The default limit of 1 MB is still in force

1Check

The default is client_max_body_size 1m. Any upload above that gets a 413 before it reaches your app.

sudo nginx -T 2>/dev/null | grep -c client_max_body_size

2Fix

Set a limit that fits your largest legitimate upload. Put it in the narrowest place that works, such as the upload location. A value of 0 turns the check off, which is rarely a good idea.

server {
    location /upload/ {
        client_max_body_size 25m;
    }
}

3Verify

Send a file just under the new limit and one over it.

head -c 20000000 /dev/zero > /tmp/test20.bin
curl -s -o /dev/null -w "%{http_code}\n" -F "file=@/tmp/test20.bin" https://example.com/upload/

Confirmed by nginx.org

Did this fix it?

Cause 2 of 2

The new value was never loaded

1Check

On reload nginx checks the new file and, if it is invalid, keeps running with the old configuration. A typo elsewhere in the file leaves the old 1 MB limit in place.

sudo nginx -t

2Fix

Fix whatever nginx -t reports, then reload.

sudo nginx -t && sudo nginx -s reload

3Verify

nginx -T now prints your value.

sudo nginx -T 2>/dev/null | grep client_max_body_size

Confirmed by nginx.org

Did this fix it?

How do I stop it coming back?

  • Set client_max_body_size per upload location, not globally, so other routes keep a small limit.
  • Keep the app-level limit (framework or PHP) equal to or below the nginx one.
  • Run nginx -t in the deploy script before every reload.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.