«

»

Jan 17

Resolve: Nginx – 413 Request Entity Too Large

Resolve: Nginx – 413 Request Entity Too Large

When working with WordPress you might come across a message that indicates HTTP Error when uploading any media to your site. Obviously there are tons of things that could cause this error, like the memory you have allocated to PHP, or even some NginX configuration might cause it. I really struggled to narrow down what the cause was as so much could cause that error but finally by performing a browser upload instead of the regular fancy upload I was able to get my web browser to throw the following error:

413 – Request Entity Too Large

Nginx 1.5.8

Another key aspect was that all my pictures I uploaded that were below 1 Mb in size were uploaded while the rest the progress bar remained at 100% without changing to calculating and on the top of the screen the HTTP Error message in red would appear. So if you want to upload files that are over 1 Mb in size simply follow this instructions:

I. Increase the Client Max Body Size in Nginx

You can do this by editing your nginx.conf file and adding the client_max_body_size directive anywhere in your http, server or location context/section (where it makes the most sense for your needs/requirements). Simply open your configuration file (in this case nginx.conf but it could be even a site configuration file as you can place this in the server/location sections) using your favorite editor like nano /etc/nginx/nginx.conf.

  • 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

There add the directive. Below you can find an example of this:

##
# Body Size (for uploads, etc)
##
# set client body size to 52M #
client_max_body_size 52M;

After that don’t forget to reload your new configuration.

II. Look out for PHP settings:

  • upload_max_filesizeMaximum allowed size for uploaded files (default: 2 megabytes). You need to increase this value if you expect files over 2 megabytes in size.
  • post_max_sizeMaximum size of POST data that PHP will accept (default: 8 megabytes). Files are sent via POST data, so you need to increase this value if you are expecting files over 8 megabytes.
Enhanced by Zemanta

Leave a Reply

%d bloggers like this: