Search
Close this search box.

How to Fix 413 Request Entity Too Large Error on NGINX

Table of Contents

You may have faced or heard of the issue when users trying to upload 1.5MB+ size image file using nginx reverse proxy, they are getting the following error on screen:

413 Request Entity Too Large

In order to fix this issue we will need to configure both nginx and php to allow upload size:

Nginx configuration

The client_max_body_size directive assigns the maximum accepted body size of client request, indicated by the line Content-Length in the header of request. If size is greater the given one, then the client gets the error “Request Entity Too Large” (413). To fix this issue edit your nginx.conf. Open the Terminal or login to the remote server using ssh client. Type the following command to edit your nginx.conf using a text editor such as vi or joe:

# vi /etc/nginx/nginx.conf
OR
# vi /usr/local/nginx/conf/nginx.conf
Add the following line to http or server or location context to increase the size limit in nginx.conf, enter:

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

Save and close the file.  Reload server:
# /usr/local/nginx/sbin/nginx -s reload
OR
# /sbin/nginx -s reload
OR use the following on RHEL/CentOS/Debian/Ubuntu Linux:

# service nginx reload

PHP configuration

Your php installation also put limits on upload file size. Edit php.ini and set the following directives

;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

Save and close the file. Make sure you reload/restart back-end apache or nginx web server as per your setup for change to take effect

 

Learn More about uptime kuma

FAQ

The “413 Request Entity Too Large Error” is an HTTP error code that is returned by NGINX web servers. It indicates that the server has received a request that is too large to process, and therefore the request is rejected.

This error is typically caused by the server’s configuration, specifically the client_max_body_size directive. By default, NGINX has a client_max_body_size value of 1 megabyte, which means that any request larger than 1 MB will result in a “413 Request Entity Too Large Error”.

You can fix the “413 Request Entity Too Large Error” on NGINX by increasing the client_max_body_size value in your NGINX configuration file. Here are the steps to do so:

  1. Locate your NGINX configuration file. This file is usually located at /etc/nginx/nginx.conf, but it can be different depending on your server setup.
  2. Open the configuration file using a text editor.
  3. Find the client_max_body_size directive, which is usually located in the http {} block of the configuration file.
  4. Increase the value of client_max_body_size to a larger number that fits your needs. For example, to allow a maximum request size of 10 MB, you can set the value to:

client_max_body_size 10M;

  1. Save the changes to the configuration file and exit the text editor.
  2. Restart the NGINX service using the command:

sudo systemctl restart nginx

 Yes, other factors such as firewall restrictions, server resource limits, and client-side settings can also cause this error. However, the most common cause is the client_max_body_size directive, as explained above.

You can prevent this error from happening again by regularly monitoring your server’s resource usage, ensuring that your NGINX configuration file is optimized for your specific needs, and educating your users on the maximum file sizes that they can upload. Additionally, you can implement client-side validation to limit the file size of requests before they are sent to the server.

Make a Comment
{{ reviewsTotal }}{{ options.labels.singularReviewCountLabel }}
{{ reviewsTotal }}{{ options.labels.pluralReviewCountLabel }}
{{ options.labels.newReviewButton }}
{{ userData.canReview.message }}
Share on
Facebook
Twitter
LinkedIn
Print
VPSie Cloud service

Fast and Secure Cloud VPS Service

Try FREE
For a month

The First 1 orders gets free discount today! Try Sign up on VPSie to get a chance to get the discount.