Fix "413 Request Entity Too Large" (Nginx, PHP, Express, Cloudflare)
413 Request Entity Too Large
- 2026/11/28 10:02:11 [error] 1234#1234: *56 client intended to send too large body: 15728640 bytes, client: 203.0.113.7, server: example.com, request: "POST /upload HTTP/2.0"
- PayloadTooLargeError: request entity too large
- PHP Warning: POST Content-Length of 9437184 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
- Illuminate\Http\Exceptions\PostTooLargeException
- HTTP 413 Content Too Large
The request body (often an uploaded file) is larger than the server accepts. On Nginx the default limit is 1 MB: raise client_max_body_size, then align upload_max_filesize and post_max_size on the PHP side, or the express.json() limit on the Node side.
What this error means
Every layer between the browser and your code sets a maximum request body size: CDN (Cloudflare: 100 MB on Free and Pro plans), proxy (Nginx: client_max_body_size 1m by default), then the application (PHP: post_max_size 8 MB and upload_max_filesize 2 MB by default; Express: 100 kB for express.json()). The first layer whose limit is exceeded rejects the request with status 413, which RFC 9110 now calls "Content Too Large". So you need to find which layer answers, then raise the limit at every level, not just the first one.
Common causes
- Default Nginx limit of 1 MB: the error page shows "nginx" at the bottom and the log contains
client intended to send too large body. - PHP limits too low:
upload_max_filesizeorpost_max_size; Laravel then throwsPostTooLargeException. - Express body-parser limit (100 kB by default):
PayloadTooLargeError: request entity too large, common with Base64 images inside JSON. - Kubernetes ingress or load balancer: ingress-nginx also applies 1 MB by default, configurable through an annotation.
- CDN limit: Cloudflare refuses beyond 100 MB (Free/Pro), 200 MB (Business) or 500 MB (Enterprise), whatever your server says.
Step-by-step fix
-
Identify the layer that answers
Look at the footer of the error page ("nginx", "cloudflare") and the
Serverheader. You can reproduce with a test file of the right size.head -c 15M /dev/urandom > /tmp/test.bin curl -s -o /dev/null -D - -F "file=@/tmp/test.bin" https://example.com/upload | grep -iE "^(HTTP|server)" -
Raise the limit in Nginx
The directive works in
http,serverorlocation. Put it as close as possible to the upload route if you do not want to open it everywhere.0disables the check: avoid it, it invites abuse.server { client_max_body_size 20m; location /upload { client_max_body_size 100m; proxy_pass http://127.0.0.1:3000; } } -
Raise the PHP limits
post_max_sizemust be greater than or equal toupload_max_filesize. Find the rightphp.ini(the PHP-FPM one, not the CLI one), then restart PHP-FPM.; /etc/php/8.3/fpm/php.ini upload_max_filesize = 20M post_max_size = 25M -
Apply and check
Reload Nginx, restart PHP-FPM, then check the values actually loaded.
sudo nginx -t && sudo systemctl reload nginx sudo systemctl restart php8.3-fpm php-fpm8.3 -i | grep -E "upload_max_filesize|post_max_size" -
Express / Node.js
Raise the limit of the relevant parser. For real files, prefer
multipart/form-datawith Multer over Base64 inside JSON (33% heavier).app.use(express.json({ limit: '10mb' })); app.use(express.urlencoded({ extended: true, limit: '10mb' })); -
Kubernetes ingress-nginx
Add the annotation on the relevant Ingress.
metadata: annotations: nginx.ingress.kubernetes.io/proxy-body-size: "20m" -
Large files behind Cloudflare
The CDN limit cannot be changed on standard plans. Send the file straight to storage (S3 or R2 presigned URL) or split it into chunks (multipart or tus upload) on the client.
Did this fix work for you?
Confirm it in one click: it will rise for the next developers stuck on the same error.
Keep it from coming back
- Set the same documented limit at every layer (Nginx, PHP or Node, application validation), with a small growing margin towards the back.
- Check the size on the client before sending to show a clear message instead of a 413 page.
- For large files, use presigned URLs to object storage instead of routing the file through your server.
Frequently asked questions
I changed php.ini but nothing changes, why?
You probably edited the CLI php.ini (/etc/php/8.3/cli/php.ini) instead of the PHP-FPM one, or forgot to restart PHP-FPM. A phpinfo() served by the site shows the file actually loaded.
In Laravel, is the max:20000 rule enough?
No: it applies after PHP has accepted the request. If Nginx or post_max_size reject it first, Laravel never sees the file. The max rule is in kilobytes.
What is the default value of client_max_body_size?
1 MB (1m). Any request whose Content-Length header exceeds it gets a 413.
Useful tools for this error
More DevOps, servers & cloud errors
- Fix "upstream timed out (110: Connection timed out)" and 504 Gateway Time-out in Nginx
- Fix "nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)"
- Fix "Certbot failed to authenticate some domains" (Let’s Encrypt, Timeout during connect, acme-challenge 404)
- Fix "Resource not accessible by integration" in GitHub Actions
- Fix the 404 on refresh of a SPA on Vercel ("404: NOT_FOUND"), Netlify and Nginx
- Fix "An error occurred (AccessDenied) when calling the PutObject operation" on AWS S3
- Fix "The connection to the server localhost:8080 was refused" with kubectl