How to avoid Request Entity Too Large 413 error

How to fix it in NGINX? client_max_body_size

To fix this, you need to increase the value of the client_max_body_size directive. This directive defines the maximum amount of data Nginx will accept in an HTTP request. By default this value is set to 1 megabyte, meaning if you attempt to upload a file larger than 1 megabyte you’ll be getting an Error 413: Request entity too large page. You can insert this directive at three levels:

  • In the http block: this will set the directive value for all server and locations in your configurationn
  • In the server block: this will set the directive value for all locations of one particular server
  • In the location block: this will set the directive value for one specific location in a particular server

In this example I’m going to insert it in my http block and set it to 500 megabytes:

http {

    client_max_body_size 500M; # allows file uploads up to 500 megabytes
    [...]
}

Leave a Comment