413 Content Too Large

The request body is bigger than the server is willing to accept. Something on the path has a size limit, and this upload or payload went over it.

What 413 means, and its three names

The server refuses the request because of the size of its body: a file upload, a large JSON document, a base64-encoded image inside a form. The size of the URL and of the headers have their own codes (414 and 431).

The code has been renamed twice. It was "Request Entity Too Large" until 2014, then "Payload Too Large", and is "Content Too Large" in the current specification. nginx still prints the oldest name on its error page. All three are the same 413.

A server may close the connection instead of reading a body it has already decided to reject. In a browser that sometimes shows as a connection reset rather than a tidy 413 page, particularly with big uploads.

Finding the limit you hit

Every layer between the client and the application has its own limit, and the smallest one wins. The error page or Server header tells you which layer answered.

LayerSettingDefault
nginxclient_max_body_size1m; 0 turns the check off
ApacheLimitRequestBody1073741824 bytes (1 GiB) since 2.4.54; unlimited before
Express (Node.js)limit option of express.json()100kb
CDN, load balancer, API gatewaySet by the provider, often by planSee their documentation

nginx's 1 MB default is the usual cause on a new server: a phone photo is larger than that. Its error log records the attempt as client intended to send too large body followed by the size in bytes.

Raising the limit

# nginx: in http, server or location
client_max_body_size 25m;

# Apache: in server config, a Directory block or .htaccess (bytes)
LimitRequestBody 26214400
  • Set it in the narrowest place that works. A 25 MB limit on /upload is safer than one on the whole site, because any endpoint that accepts large bodies can be used to tie up bandwidth and disk.
  • Raise the application's limit to match. With PHP that means post_max_size and upload_max_filesize. PHP does not send a 413 when those are exceeded; the upload just arrives empty.
  • Reload the server and test with a file slightly under and slightly over the new limit.

If you cannot change the server

  • Send less. Resize or compress images before upload, and send files as multipart/form-data or raw bytes instead of base64 inside JSON, which adds a third to the size.
  • Send it in parts. Use the API's chunked or resumable upload if it has one.
  • Upload elsewhere. Many APIs hand out a pre-signed URL so the file goes straight to object storage and only a reference passes through the API.
  • Ask first. A client can send Expect: 100-continue with the headers and wait for the go-ahead, so a refusal costs no upload time. curl does this by itself for large bodies.

If the condition is temporary, for instance a quota that resets, the server should say so with a Retry-After header. Without one, assume the limit is fixed and do not retry the same body.

413 compared with 414, 431, 400 and 408

CodeWhat was too big or too slow
413 Content Too LargeThe request body
414 URI Too LongThe URL, usually a huge query string
431 Request Header Fields Too LargeThe headers, usually cookies; many servers send 400 for this instead
408 Request TimeoutNothing was too big; the body arrived too slowly

Example 413 response

HTTP/1.1 413 Content Too Large
Content-Type: application/json
Content-Length: 110
Connection: close

{"error":"content_too_large","message":"Upload is 31457280 bytes; the limit is 26214400","max_bytes":26214400}

Stating the limit in bytes lets a client check sizes before uploading next time. Connection: close reflects that the server is not going to read the rest of the body.

Defined in RFC 9110, section 15.5.14.

Questions

How do I fix "413 Request Entity Too Large" in nginx?

Raise client_max_body_size, which defaults to 1m. Put it in the http, server or location block that handles the upload, for example client_max_body_size 25m; then reload nginx. Check that the application behind it accepts bodies of that size too.

Is 413 Payload Too Large the same as 413 Content Too Large?

Yes. Request Entity Too Large, Payload Too Large and Content Too Large are successive names for the same status code. The number is what clients act on; the text after it varies between servers.

Why do I get a connection reset instead of a 413 when uploading?

The server rejected the body and closed the connection while your client was still sending. Some clients report the broken connection before they read the 413 response. The cause and the fix are the same as for a visible 413.

What is the maximum upload size in Apache?

LimitRequestBody sets it. Since version 2.4.54 the default is 1 GiB (1073741824 bytes); earlier versions had no limit by default. Setting it to 0 removes the limit.