Find which size limit stopped the upload

413 Content Too Large means the server refused a request because its body, usually an uploaded file or a large form or API payload, was bigger than it will accept. It's the same status older specifications called Request Entity Too Large and Payload Too Large, and nginx still prints the oldest name. Every layer between the visitor and your app can set its own limit, so find the one that refused the request and raise it there, or keep uploads under it.

Which limit refused the request

  • The web server

    Web servers cap the request body, and the default can be small. nginx, for example, accepts 1 megabyte unless it's configured otherwise. IIS answers a request whose Content-Length passes its limit with 404.13, content length too large, instead of 413.

  • A CDN, proxy or load balancer

    Services in front of your server set their own body limits and refuse a larger request before your server sees it. Amazon's load balancer, for example, refuses bodies over 1 MB when it forwards to a Lambda function.

  • Your app or framework

    Body parsers in web frameworks have a default size of their own. Express's body parser defaults to 100 KB and answers 413 with a request entity too large error when a body passes it.

  • Oversized headers, on some servers

    Some load balancers answer 413 when the request headers, not the body, pass their limit, so check large cookies too when no upload is involved.

RFC 9110 names the status Content Too Large; RFC 7231 called it Payload Too Large and RFC 2616 Request Entity Too Large. The limits come from nginx's documentation, Amazon's load balancer guide and Express's body-parser readme. Microsoft's IIS status code list gives the 404.13 code.

Find the size where uploads start failing

# See which server answers visitors first
curl -sI https://yoursite.com/ | grep -iE '^(HTTP|server)'

# Make 1 MB and 10 MB test files, post each one as a form upload and print the status
head -c 1000000 /dev/zero > test-1mb.bin
head -c 10000000 /dev/zero > test-10mb.bin
for f in test-1mb.bin test-10mb.bin; do
  printf '%s ' "$f"; curl -s -o /dev/null -w '%{http_code}\n' -F "file=@$f" https://yoursite.com/upload
done

Read the result

  • The size where the status changes to 413 is the smallest limit along the path. Look at the error page that comes back to see who set it: a bare page that names the web server, a page branded by your CDN, or an error in your app's own format. Raising a limit only helps at the layer that refused the upload.

  • A visitor may never see the 413 page. RFC 9110 lets the server close the connection instead of reading the rest of the body, and nginx's documentation warns that browsers can't display its 413 correctly. In the curl test, that can show up as 000 instead of a status, and in a browser as a generic connection failure.

How to fix a 413 Content Too Large error

  1. Decide the largest upload you'll acceptBase it on what visitors need to send, such as photos or PDFs, and set every layer to accept at least that much on the upload route.
  2. Raise the limit layer by layer, from the outside inStart with the CDN or load balancer, then the web server, then the app. Raising only the app's limit changes nothing while a layer in front still refuses the request.
  3. Check the size in the browser firstRead the file's size before the upload starts and show the limit next to the field, so visitors don't sit through an upload that's going to fail.
  4. Send big files straight to storageFor files larger than your server should handle, upload directly to object storage with a short-lived signed address, and keep your own server's limit low.

Frequently asked questions

Is Request Entity Too Large the same error as 413?

Yes. RFC 2616 named status 413 Request Entity Too Large, RFC 7231 renamed it Payload Too Large and RFC 9110 renamed it Content Too Large. The meaning never changed, and MDN notes that Payload Too Large is still widely used.

Is it risky to raise the upload limit?

A higher limit lets each request take more of the server's memory, disk and time. Raise it only on the routes that accept uploads, keep it low everywhere else, and check file types and sizes in your app as well. The body-parser readme warns that large limits raise memory use and response times.