Nginx Error 413

Fixing 413 Request Entity Too Large

Nginx Error 413

Error “413 Request Entity Too Large” is a very common error in Apache and NGINX web servers, which appears when someone requests more information than is what limited by PHP or by Apache/NGINX configurations.

It can be found on standalone Apache/NGINX web server or while proxy based solutions when NGINX acts as a front end server for Apache at back end server. In this guide I will explain you how to fix this error 413 request entity is too large in Apache as well as in NGINX.

When it Occurs?

As the error says request entity too large, it occurs when a request made by client is trying to access or process more information than what is limited by Apache/NGINX and PHP configuration file. Mostly it occurs when you have everything setup in default mode (means just installed software and left all settings to default).

How to Fix 413 Request Entity Too Large Errors?

Here we need to allow more memory to web server Apache/NGINX whatever you use and to PHP for dynamic contents.

How to Fix it? Apache Users

Edit .htaccess file and add the below directive in it.

LimitRequestBody 104857600

Now restart Apache.

sudo service apache2 reload

How to Fix it? Nginx Users

It can be fixed by increasing the memory limit in nginx as well as PHP configuration file.

In order to fix this issue, we need to edit nginx.conf file.

sudo nano /etc/nginx/nginx.conf

Search for this variable: client_max_body_size. If you find it, just increase its size to 100M, for example. If it doesn’t exist, then you can add it inside and at the end of http { … } block.

client_max_body_size 100M;

Restart nginx to apply the changes.

sudo service nginx restart

Modify PHP.ini File to Increase Upload Limits

It’s not needed on all configurations, but you may also have to modify the PHP upload settings as well to ensure that nothing is going out of limit by php configurations.

Here we need to edit php.ini file.

Note: Since there are 2 versions of PHP is being used world wide (PHP5-fpm and PHP7.0-fpm) I have specified both the commands, use one of them only whichever you are using.

If you are using PHP5-FPM use following command,

sudo nano /etc/php5/fpm/php.ini

If you are using PHP7.0-FPM use following command,

sudo nano /etc/php/7.0/fpm/php.ini

Now find following directives one by one…


…and increase its limit to 100M, by default they are 8M and 2M.

upload_max_filesize = 100M
post_max_size = 100M

Finally save it and restart PHP.

PHP5-FPM users use this,

sudo service php5-fpm restart

PHP7.0-FPM users use this,

sudo service php7.0-fpm restart

You can set any limit to Apache/Nginx and PHP configuration files, here we have set them to 100M means 100 Mega Bytes which is more than enough that we needed.

Written by
Join the discussion

  • Thanks for nice tutorial, I am using DigitalOcean VPS and installed NGINX and PHP-FPM with WordPress. I was facing the same issue of 413 request entity too large whenever I tries to upload bigger files like infographics and high quality images. By adding your codes in configuration files now I am able to upload bigger files as well.

  • How do I fix this problem and allow image upload upto 2MB in size using nginx web-server working in reverse proxy or stand-alone mode on Unix like operating systems?

    • Hi Julia, the syntax used in the post remains same for the Unix OS too. If you want to allow 2MB of file or image in your case then add following code in nginx.conf inside http directive.

      client_max_body_size 2M;

      After adding this live save nginx.conf and reload/restart nginx. Also follow above tutorial and change values in PHP configs too. In most cases I suggest to keep them upto 8MB to 32MB because hardly there would be any file larger than this.