DevOpsil
NginxMedium

Fix: Nginx 413 Request Entity Too Large

File uploads fail with '413 Request Entity Too Large'

!Symptoms

  • File uploads fail with '413 Request Entity Too Large'
  • POST requests with large bodies are rejected
  • Only large files fail, small files work fine

?Root Causes

  • Nginx client_max_body_size is set too low (default is 1MB)
  • Multiple Nginx config levels overriding each other (http, server, location)
  • Reverse proxy or CDN in front of Nginx also has a body size limit
  • Application framework has its own body size limit (Express, PHP, etc.)

#Diagnosis Steps

  1. 1Check Nginx config for client_max_body_size: `nginx -T | grep client_max_body_size`
  2. 2Determine the size of the failing request body
  3. 3Check all config levels (http, server, location) for conflicting settings
  4. 4Check if a CDN (CloudFlare, etc.) is also limiting: CloudFlare free plan limits to 100MB

>Fix

  1. 1Set client_max_body_size in Nginx config: `client_max_body_size 50m;` in the appropriate block
  2. 2Add it at the server or location level, not just http level
  3. 3Reload Nginx: `nginx -t && systemctl reload nginx`
  4. 4Also increase application-level limits (e.g., PHP upload_max_filesize, Node bodyParser limit)
  5. 5If behind CDN, increase upload limit there too

*Prevention

  • Set client_max_body_size explicitly in all server blocks that handle uploads
  • Document maximum upload sizes in API documentation
  • Implement client-side file size validation before upload
  • Use multipart/chunked uploads for very large files
  • Test file upload limits as part of deployment verification

Related Error Messages

413 Request Entity Too Largeclient intended to send too large bodyPayloadTooLargeError