How to Fix Nginx Error 413: Request Entity Too Large

Error 413 is a very common Nginx error. It can be found on Nginx as a stand alone server or while using proxy-based solutions, when Nginx is acting as a front end server for Apache on the back end.

This error occurs when your applications is trying to get more information than what is limited by the PHP configuration. Nginx has a directive called client_max_body_size. This variable assigns the maximum accepted body size of any request made by the client.

You can see this in the web headers at the Content-Length line. If the size is greater than the one your PHP is running, you will get a “Request Entity Too Large” (413) error.

In order to fix this issue, you will have to edit the nginx.conf main configuration file.

Search for this variable: client_max_body_size. If you find it, just increase its size to 8M, for example. If it doesn’t exist, then you can add it:

vim /etc/nginx/nginx.conf
client_max_body_size 8M;

Reload Nginx to apply the changes:

service nginx reload

It’s not needed on all configurations, but you may also have to modify the PHP upload settings. Then, you’ll move to the last step to modify your upload general PHP configuration:

Find your php.ini file and modify it using nano. Example: (CentOS path is /etc/php.ini) or (Debian path is /etc/php5/fpm/php.ini)

vim php.ini
; Modify the maximum size of uploaded files:
upload_max_filesize = 8M
; Modify the maximum size of post data:
post_max_size = 8M

Finally, reload Nginx to apply the changes:

service nginx reload

At this time, you should be able to try this configuration with 8M or even more. It all depends on how much information your app is requesting from the client. Tweak as needed.