Fix: 413 Request Entity Too Large
A server or proxy rejected your request because its body is bigger than the configured limit. Find which layer set the limit, then raise it carefully or send less data.
Not checked by a trusted editor yet Last edited Outdated?
You upload a file or post a large JSON body and get back this status, often as a bare HTML page from nginx:
413 Request Entity Too Large
Some layer between the client and your code has a maximum request body size, and your request exceeded it. Current HTTP specs (RFC 9110) call the status 413 Content Too Large; the older name is still what many servers print. Your application code may never have seen the request.
Find the layer that answered
Look at the response headers and body. A Server: nginx header with a plain HTML error page points to nginx. A JSON body or a framework error such as Express’s PayloadTooLargeError: request entity too large points to your app. A load balancer or CDN may have its own message. Fix the layer that actually responded, but remember that every layer in front of the app needs a limit at least as large.
nginx
nginx limits bodies with client_max_body_size, which defaults to 1 MB. Set it in the http, server, or location block that handles the request:
server {
# ...
location /api/upload {
client_max_body_size 25m;
proxy_pass http://127.0.0.1:3000;
}
}
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
sudo nginx -t && sudo systemctl reload nginx
Express (Node.js)
The built-in body parsers default to a 100 kB limit. Raise it only where needed:
app.use(express.json({ limit: "1mb" }));
app.post("/api/import", express.json({ limit: "10mb" }), importHandler);
For file uploads, use a streaming multipart library such as multer, which has its own size options, rather than reading files into JSON.
Flask
Flask rejects bodies larger than MAX_CONTENT_LENGTH with a 413:
app.config["MAX_CONTENT_LENGTH"] = 16 * 1024 * 1024 # 16 MB
Apache, PHP, and others
- Apache httpd:
LimitRequestBody. - PHP:
upload_max_filesizeandpost_max_sizeinphp.ini. - Kubernetes with the ingress-nginx controller: the
nginx.ingress.kubernetes.io/proxy-body-sizeannotation. - Managed load balancers and CDNs: check the provider’s documented request size limits; some cannot be raised.
Consider sending less instead
Raising limits everywhere makes it easier to exhaust memory or disk with oversized requests. Often a better fix is on the client side:
- Upload large files directly to object storage with pre-signed URLs, so they never pass through your app.
- Split big uploads into chunks, or paginate large imports.
- Compress or resize images in the browser before upload.
- Send file references instead of Base64-encoded file contents inside JSON, which inflates size by about a third.
Check the fix
head -c 2000000 /dev/zero > /tmp/test-2mb.bin
curl -s -o /dev/null -w '%{http_code}\n' \
--data-binary @/tmp/test-2mb.bin \
-H 'Content-Type: application/octet-stream' \
http://localhost:8080/api/upload
A 413 means a limit is still too low; any other code means the body got through to the next layer.
Did this work for you?
No votes yet. Be the first.
If it did not work, the report form below tells the editors what went wrong.
See also
- 0082 HTTP status codes: the common ones and what to do A quick reference to the HTTP status codes you will meet most often, what each one means, and the first thing to… Beginner · Cheat sheet · Any system Article References · Status codes 15 Oct 2026
- 0263 Build a notes REST API with plain Node.js: CRUD, validation, status codes and CORS Write a small JSON API for notes using only Node.js built-ins: create, read, update and delete, input validation, correct HTTP status codes,… Intermediate · Guided project · Any system Article Making requests · Node.js · Status codes 15 Oct 2026
- 0302 What is a status code? A status code is the three digit number a web server returns to say whether a request worked, like 200 OK or… Beginner · Explains an idea · Any system Article Status codes 15 Oct 2026
Repos in the wild
- Tailwind CSS (tailwindlabs/tailwindcss) tailwindlabs/tailwindcss A utility-first CSS framework: you style elements with small single-purpose classes in your HTML, and the build step generates only the CSS you actually use. GitHub
- Flask (pallets/flask) pallets/flask A lightweight Python web framework for building websites and JSON APIs, with routing, request handling, and templates, and extensions for everything else. GitHub
- Express (expressjs/express) expressjs/express A minimal and flexible web framework for Node.js, built around routes and middleware, and the foundation of countless APIs and other frameworks. GitHub
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Commitpedia +2,941 chars