Nginx Upload limitation

We often receive customer’s tickets indicates error ‘413 – Request Entity Too Large’. This is an Nginx error stated that web server rejecting too large files. What a large file replied customers, I even liked to upload a 5M photo. In this article we will show how to fix this limit.

First of all Nginx configured to restrict files by size. You may set to allow the maximum size of the client request body using directive ‘client_max_body_size’ in Nginx configuration.

If the size of a request exceeds the configured value, the 413 (Request Entity Too Large) error returned to the client.

Fixing ‘413 – Request Entity Too Large’ error

To fix this limit we have to edit nginx.conf on our server. Open the Terminal App (on Mac) or Putty (on Windows) and setup remote connection to your server via SSH. After establishing a connection we suggest to locate nginx.conf via mc (Midnight Commander) and launch editor (F4).

$ cd /etc/nginx/

or you may use ‘vi’ to edit this config:

$ vi /etc/nginx/nginx.conf

Customizing an Nginx configuration file

1. Open the config file and search for a string:

# set client body size to 2M #
client_max_body_size 2M;

2. Change default value 2M to your custom setting, we recommend 32M. This will be enough for most websites.

3. After saving nginx.conf you have to reload Nginx webserver. Type:

# service nginx reload

Another problem – PHP upload limits

After increasing Nginx value files are still not uploading. This causes you have another bottleneck with file uploading limits. Sometime this seen in PHP.

Go to you PHP location (php.ini) and edit the file:

# This sets the maximum amount of memory in bytes that a script is allowed to allocate
memory_limit = 32M

# The maximum size of an uploaded file.
upload_max_filesize = 2M

# Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize
post_max_size = 3M

You should adjust file size up to the high limits in Nginx configuration. After changing php.ini please restart php-fpm:

$ sudo systemctl restart php-fpm

Looking for a custom solution?

Our technicians can provide you with the best custom made solutions on the market, no matter whether you're a small business or large enterprise.

Get in touch