How to fix 413 Request Entity Too Large in nginx

If you’re encountering the “413 Request Entity Too Large” error in Nginx, it means the server is rejecting requests that exceed the configured size limit. You can fix this by increasing the client_max_body_size directive in your Nginx configuration.

Steps to Increase Request Size:

  1. Edit the Nginx Configuration File
    Open your Nginx config file (nginx.conf or site-specific config in /etc/nginx/sites-available/):sudo nano /etc/nginx/nginx.conf Or, if modifying a specific site:sudo nano /etc/nginx/sites-available/default
  2. Increase client_max_body_size
    Add or modify the following line inside the http, server, or location block:client_max_body_size 100M; Adjust the value (100M) based on your needs.
  3. Save and Exit
    • If using nano, press CTRL + X, then Y, and Enter to save.
  4. Restart Nginx to Apply Changes
    sudo systemctl restart nginx
  5. Verify Configuration
    Check if the changes were applied correctly:sudo nginx -t

If you’re also using PHP-FPM, you may need to adjust upload_max_filesize and post_max_size in php.ini.

Leave a Reply