Skip to content
  1. LuzineDebug
  2. DevOps, servers & cloud
  3. 413 Request Entity Too Large
DevOps, servers & cloud Beginner ≈ 10 min to fix

Fix "413 Request Entity Too Large" (Nginx, PHP, Express, Cloudflare)

Error message
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
In short

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.

Be the first to confirm this fix

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

  1. 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.
  2. PHP limits too low: upload_max_filesize or post_max_size; Laravel then throws PostTooLargeException.
  3. Express body-parser limit (100 kB by default): PayloadTooLargeError: request entity too large, common with Base64 images inside JSON.
  4. Kubernetes ingress or load balancer: ingress-nginx also applies 1 MB by default, configurable through an annotation.
  5. CDN limit: Cloudflare refuses beyond 100 MB (Free/Pro), 200 MB (Business) or 500 MB (Enterprise), whatever your server says.

Step-by-step fix

  1. Identify the layer that answers

    Look at the footer of the error page ("nginx", "cloudflare") and the Server header. You can reproduce with a test file of the right size.

    bash
    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)"
  2. Raise the limit in Nginx

    The directive works in http, server or location. Put it as close as possible to the upload route if you do not want to open it everywhere. 0 disables the check: avoid it, it invites abuse.

    nginx
    server {
        client_max_body_size 20m;
    
        location /upload {
            client_max_body_size 100m;
            proxy_pass http://127.0.0.1:3000;
        }
    }
  3. Raise the PHP limits

    post_max_size must be greater than or equal to upload_max_filesize. Find the right php.ini (the PHP-FPM one, not the CLI one), then restart PHP-FPM.

    ini
    ; /etc/php/8.3/fpm/php.ini
    upload_max_filesize = 20M
    post_max_size = 25M
  4. Apply and check

    Reload Nginx, restart PHP-FPM, then check the values actually loaded.

    bash
    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"
  5. Express / Node.js

    Raise the limit of the relevant parser. For real files, prefer multipart/form-data with Multer over Base64 inside JSON (33% heavier).

    javascript
    app.use(express.json({ limit: '10mb' }));
    app.use(express.urlencoded({ extended: true, limit: '10mb' }));
  6. Kubernetes ingress-nginx

    Add the annotation on the relevant Ingress.

    yaml
    metadata:
      annotations:
        nginx.ingress.kubernetes.io/proxy-body-size: "20m"
  7. 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

All DevOps, servers & cloud errors →