Methods of payment Abuse

What error 413 means and how to fix it

07.07.2024, 23:21

In rare cases, but it happens that while uploading large files to a website, an error is returned by the Nginx web server - 413 Request Entity Too Large. The error appears when you try to upload a file that is too large than allowed on the server. Next, let's look at the description of the 413 Request Entity Too Large error and methods of fixing it on the Nginx web server side.

What error 413 means

Error 413 or Request Entity Too Large stands for "Request Entity Too Large" or in simple words the amount of data being transferred is too large. The error is returned when the server cannot process a request because the request body (or large file) is too large. A screenshot of the error screen is shown below:

By default, Nginx has a request body size limit of 1MB. If the request exceeds the set value, you will see error 413 Request Entity Too Large.

Why the error appears

The 413 "Request Entity Too Large" error occurs when a web server rejects a request because the request body size exceeds the maximum allowed size set on the server. This means that the data sent in the request (for example, when uploading a file to the server) is too large to process.

Resolve the problem:

  1. By changing the server settings: you can try to increase the maximum allowable request size on the server. This may require changing the web server configuration files - Apache, Nginx.
  2. Reducing the size of the data: if possible, try to reduce the size of the data sent in the request. For example, if you are uploading a file, try reducing its size.
  3. Using other data transfer methods: instead of one large request, you can divide the data into several smaller requests and send them piecemeal.
  4. Using other file transfer methods: You can use specialized file sharing services or FTP to transfer large files.

If you do not control the server to which you are sending the request, contact your server administrator or technical support for assistance in resolving the 413 "Request Entity Too Large" error.

How to fix

To fix error 413, you should increase the allowable limit. You can increase the size of the request body and, consequently, the size of uploaded files by using client_max_body_size. The option is available for use in the http, server or location directives in the /etc/nginx/nginx.conf configuration file or in the website configuration file.

Open the nginx.conf configuration file using any text editor:

$ sudo nano /etc/nginx/nginx.conf

Type a line in the http section:

$ client_max_body_size 100M

100 - the maximum file size in megabytes that can be uploaded to the website, in this case 100 megabytes. If there are several websites at your disposal and it is necessary to restrict uploading to all websites at once, then the client_max_body_size line should be entered into the http block section.

If it is necessary to restrict downloading only for a particular site, then the client_max_body_size line should be added to the server block of the site configuration file, which by default is located in /etc/nginx/sites-available/file_name_with_configuration:

When a download limit needs to be set only for a specific section on a site, the client_max_body_size string must be added to the location directive of the site configuration file, which is located by default in /etc/nginx/sites-available/file_name_with_configuration:

Once the changes have been made to the configuration files, save them, close the text editor and check the syntax of the configuration files for errors using the command:

$ sudo nginx -t

You may see the following lines:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

This means that there are no errors. Otherwise, you will see a description of the error, the name of the file where the error was found and the line number. After making any changes to the Nginx configuration files, you should restart them using the command:

$ sudo systemctl reload nginx

This article covered an error in Nginx known as 413 Request Entity Too Large, which occurs when uploading large files to a website. In addition to describing the error itself, steps to fix the error by editing Nginx configuration files were also described.