How to Fix Nginx Error “413 Request Entity Too Large”

The error “413 Request Entity Too Large” indicates that web server configured to restrict large file size. Nginx can be set to allow the maximum size of the client request body using “client_max_body_size” directive. If the size of a request exceeds the configured value, the 413 (Request Entity Too Large) error returned to the client

STEPS TO FIX IT:

Step 1: Open the nginx configuration file, example using “vi”.

sudo vi /etc/nginx/nginx.conf

Step 2: Adding new line (Or update old line if it is there) with your value.

  • Set in “http” block which affects all server blocks (virtual hosts)
  • Set in “server” block, which affects a particular site/app.
  • Set in “location” block, which affects a particular directory (uploads) under a site/app.
  • Setting size to 0 disables checking of client request body size.

Example on “http” block: limit to 50m

http {
    ...
    client_max_body_size 50m;
}

Step 3: Reload Nginx (No need to restart)

sudo systemctl reload nginx

Now you’re able to upload file with max 50m. You can update the number as you want depends on how strong your your server 🙂


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *