The"request header or cookie too large
" error in Nginx occurs when the size of request headers or cookies exceeds the maximum allowed size, which is set in the server configuration. In this article we will analyze in detail why this happens.
The error occurs when the size of HTTP/HTTPS request headers exceeds the allowed limit. For example, the browser is sending too many cookies or the request sent to the web server is too large.
The request is usually divided into two parts: headers - where general information and meta data is located, and the request body. The request body, as well as the header can be of different sizes - both small and large and its size usually does not cause any problems. However, if the web server settings have a parameter to limit the length of the request header, you are likely to get this error.
There are several ways to fix the problem
nginx.conf
configuration file.POST
request instead of GET
. If the problem occurs when sending a GET
request with large parameters, you can try using a POST
request instead of GET
.To fix this error (if you are a Nginx web server administrator), you should increase the maximum header size by changing the large_client_header_buffers
parameter. If you are an ordinary user of the website where this error occurred, you should wait until the administrator of the resource corrects the error.
You need to adjust the large_client_header_buffers
parameter, which takes 2 numbers, for example 4 and 8 (which are set by default). The first number is the value that sets the maximum number of buffers, and the second number is the size of the buffer that the request header is read into. The second parameter is specified in kilobytes.
This line is added to the http section of the Nginx configuration file or to the server section for a particular site. Nginx website configuration files are usually stored in /etc/nginx/conf.d/
or /etc/nginx/sites-available/
(depending on how Nginx was installed - using standard operating system repositories or using Nginx repository).
To adjust the value you can set the numbers 8 and 64 suitable for storing large headers. The parameter will look like this:
large_client_header_buffers 8 64k;
Once changes have been made to the configuration file, Nginx must be restarted using the command:
sudo systemctl reload nginx
These are the methods to fix this problem.