Categories
Technology

How to Fix 413 Request Entity Too Large?

The error “413 Request Entity Too Large” is a very common error occurs with Apache or Nginx web servers. It appears when someone requests more information than is what limited by Apache or Nginx and by PHP configurations.

Nginx Error 413

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 how to fix this error “413 request entity is too large” in Apache as well as in Nginx, and definitely in PHP as well.

When it Occurs?

As the error says request entity too large, it occurs when a request made by the client is large and 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 set up in default mode (means just installed software and left all settings as it is).

How to Fix 413 Request Entity Too Large Errors?

Here we need to allow more memory to the webserver to fix this issue.

Apache Users: Fix 413 Request Entity Too Large

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

LimitRequestBody 104857600

Now restart Apache.

sudo service apache2 reload

Now fix PHP limits as well to fix this issue.

Nginx Users: Fix 413 Request Entity Too Large

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 the Nginx to apply the changes.

sudo service nginx restart

Now fix PHP limits as well to fix this issue.

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 the php.ini file.

Note: You need to identify yourself what version of PHP is installed on the webserver in order to edit that. We are using PHP 7.3 so we have used commands for that.

nano /etc/php/7.3/fpm/php.ini

Now find following directives one by one…

upload_max_filesize
post_max_size

…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 the PHP.

service php7.3-fpm restart

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

By AtulHost

Hi, I'm Atul Kumar Pandey; also known as AtulHost on the web, a full-time blogger by profession with an objective of sharing fresh and honest contents in business and technology niche.

5 replies on “How to Fix 413 Request Entity Too Large?”

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.

Comments are closed.