Nginx 413 Request Entity Too Large (client_max_body_size)

Nginx refuses request bodies over 1MB by default. Uploads fail with 413 even though your app would accept them — the limit must be raised where Nginx terminates the request.

What you'll see

Root causes

Default client_max_body_size is 1m

Unless you raise it, Nginx rejects bodies >1MB at the edge. Your app never sees the request — there's nothing to debug in the app.

Directive set in the wrong context

client_max_body_size in a location block that doesn't match the upload route, or a server block overriding the http-level value. nginx -T shows the effective merged config.

Fix it

  1. See the effective value in the running config
    sudo nginx -T 2>/dev/null | grep -n client_max_body_size
  2. Raise it for the upload route (or server)
    # in the relevant server or location block:
    # client_max_body_size 50m;
  3. Validate and reload
    sudo nginx -t && sudo systemctl reload nginx
  4. Match upstream limits so they don't fail next
    # behind a proxy also set: proxy_request_buffering off;  # or size app/PHP limits (php: upload_max_filesize, post_max_size)

Field note

Behind Cloudflare, free-plan uploads also cap at 100MB — 413 from Cloudflare mentions cloudflare in the response headers. Raising limits too high invites abuse; scope the directive to the specific upload location.

Common questions

I set client_max_body_size but still get 413. Why?

The directive is probably in the wrong context — check nginx -T for the merged effective value on your exact server/location, and confirm another server block isn't handling the request. Then reload nginx; a restart isn't needed.

Does client_max_body_size affect normal page speed?

No — it only limits request body size (uploads, POSTs). Raising it doesn't change behavior for typical GET requests.

Ship it right the first time

Our most-documented failures, packaged as ready-to-ship starter kits: Docker, Kubernetes, and Terraform.

Browse the template store →

One-time. Yours to modify. Instant download from the NinjaOps template store.