Are you having trouble uploading files to your website running on an nginx web server? If you are getting the nginx 413 Request Entity Too Large error, there is probably a simple fix. Be sure to check these items to resolve the problem.
I love setting up WordPress websites on nginx web servers. I’ve been doing quite a bit of that recently as I’ve been migrating a lot of sites from Ubuntu 14.04 to 16.04 servers. One “gotcha” is that if you forget to update the server settings, you might run into various errors.
(Re)Discovering the Nginx 413 Request Entity Too Large Error
One common error with nginx is the 413. The description does a pretty good job of explaining what the problem is. You can probably intuit from the message that this error is caused by a user sending too much data in an HTTP request. Typically, this is due to either a large file upload or too much POST data being sent by the client.
How to fix it
To fix this error, all you need to do is 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 get this 413 Request Entity Too Large page.
To set a higher value, simply write a directive like this:
client_max_body_size 100M; (The value can be modified to suit your particular situation–100M is just an example, and it will allow uploads up to 100 Mb). Then put that directive in one of the following three places:
- 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
For example, if you put it in a server block, it will look like this:
Once you’ve changed your config files, test the changes:
sudo nginx -t
If the test passes, restart nginx:
sudo systemctl restart nginx
Don’t Forget Your PHP Settings
Once you’ve changed the PHP settings, be sure to restart PHP. For instance, on my servers I used this command:
sudo systemctl restart php7.0-fpm