413 Request Entity Too Large: which limit stopped the upload?
Between the browser and your code there are usually four separate size limits, and raising the wrong one changes nothing. Here is how to tell which layer sent the 413, the defaults for each, and the PHP case where an oversized form is not rejected at all.
A customer tries to upload a 12 MB brochure and gets a plain white page that says
413 Request Entity Too Large. You raise upload_max_filesize, try again, and get exactly
the same page. That is normal: there are several size limits stacked between the browser and your code, and the
one you raised was not the one that answered.
What does 413 Request Entity Too Large mean?
It means a server refused the request because its body was larger than that server is configured to accept. The
body is everything sent after the headers: a file upload, a submitted form, a JSON payload from an API client. The
current HTTP specification names the status 413 Content Too Large, and you will also see
Payload Too Large, but older software still prints "Request Entity Too Large". All three mean the
same thing.
Which limits sit between the browser and your code?
On a typical production stack, the request passes through up to four layers, and each has its own cap:
- A CDN or proxy. Cloudflare caps a request body at 100 MB on the Free and Pro plans and 200 MB on Business. A larger upload is rejected before it ever reaches your server.
- The web server. nginx's
client_max_body_sizedefaults to just 1 MB, which a single phone photo can exceed. Apache'sLimitRequestBodywas unlimited for years and defaults to 1 GB since version 2.4.54. - The runtime. PHP has
post_max_size, 8 MB by default, andupload_max_filesize, 2 MB by default. Express's built-inexpress.json()andexpress.urlencoded()parsers cap a body at 100 KB and throwPayloadTooLargeError: request entity too large. - The application. Your own validation, or the platform's: WordPress refuses a file that "exceeds the maximum upload size for this site", which it reads from PHP's two settings.
How do you tell which layer sent the 413?
Look at the error page itself, and at the response headers in your browser's Network tab. Each layer answers in its own style:
- A page branded by Cloudflare, or a response with a
cf-rayheader and no request in your server logs, means Cloudflare refused it. - A bare white page that says
413 Request Entity Too Largewithnginxunderneath is nginx. - A JSON error from your API, or an Express stack trace in the app log mentioning
entity.too.large, is the body parser in your Node app. - No 413 at all, but a form that arrives empty or a WordPress upload error, is PHP. That case is special enough to get its own section.
Why does PHP sometimes accept the form but lose the data?
Because PHP does not answer with a 413. When a request body is bigger than post_max_size, PHP logs a
warning, POST Content-Length of 11184886 bytes exceeds the limit of 8388608 bytes, and then runs your
script anyway with $_POST and $_FILES completely empty. To your code, it looks as if
the user submitted a blank form.
That has consequences far from the upload. The form's hidden fields are gone too, including any CSRF token, so a
Laravel app answers with 419 Page Expired instead of anything about
size. When only a single file is too big for upload_max_filesize while the whole request still fits
post_max_size, the rest of the form arrives and that file's entry in $_FILES carries
error code UPLOAD_ERR_INI_SIZE, the value 1. Check that error code before you touch the file.
if ($_SERVER['REQUEST_METHOD'] === 'POST' && empty($_POST) && empty($_FILES)
&& (int) ($_SERVER['CONTENT_LENGTH'] ?? 0) > 0) {
// the body was larger than post_max_size: tell the user, do not treat it as an empty form
}
How do you raise the limit safely?
Work from the outside in, and raise each layer only as far as your largest legitimate upload needs. For a 50 MB limit on a PHP site behind nginx:
# nginx, in the location that handles uploads
client_max_body_size 50M;
; php.ini, or php_admin_value[...] in the PHP-FPM pool
upload_max_filesize = 50M
post_max_size = 55M
Keep post_max_size a little larger than upload_max_filesize, since the form fields travel
in the same request as the file, and keep memory_limit above both. Reload nginx and PHP-FPM after the
change. A large upload also takes time to arrive, so the
execution and read timeouts may be the next limit it
meets.
In Express, raise the parser limit only on the routes that need it, for example
express.json({ limit: '5mb' }) on one endpoint, and use a dedicated multipart handler with its own
limits for real file uploads. For very large files, uploading straight from the browser to object storage with a
presigned URL avoids every one of these layers and keeps your app servers out of the transfer entirely.
Found something wrong in here? Tell me.