Docs / Troubleshooting / How to Fix Nginx 413 Request Entity Too Large Error

How to Fix Nginx 413 Request Entity Too Large Error

By Admin · Mar 1, 2026 · Updated Apr 23, 2026 · 30 views · 2 min read

What Causes This Error?

The Nginx 413 error occurs when a client sends a request body that exceeds the client_max_body_size directive. This commonly happens during file uploads. By default, Nginx limits request bodies to just 1 MB.

Quick Fix

Increase the client_max_body_size directive in your Nginx configuration:

# In /etc/nginx/nginx.conf (http block, applies globally)
http {
    client_max_body_size 64M;
}

# Or in a specific server block
server {
    client_max_body_size 64M;
}

# Or in a specific location block
location /upload {
    client_max_body_size 128M;
}

Apply the Change

# Test configuration syntax
sudo nginx -t

# Reload Nginx
sudo systemctl reload nginx

Also Update PHP (If Applicable)

If your application uses PHP, you must also update PHP upload limits:

# Find your php.ini
php --ini | grep "Loaded"

# Edit php.ini
sudo nano /etc/php/8.2/fpm/php.ini

Set these values to match or exceed your Nginx limit:

upload_max_filesize = 64M
post_max_size = 64M

Then restart PHP-FPM:

sudo systemctl restart php8.2-fpm

Verification

Test a large file upload through your application or with curl:

curl -X POST -F "file=@largefile.zip" https://yourdomain.com/upload

Best Practice

  • Set limits as low as practical for your use case
  • Use location-specific overrides for upload endpoints rather than increasing globally
  • Monitor upload activity in your Nginx access logs

Was this article helpful?