Nginx How to solve the super long request string

Source: Internet
Author: User

Nginx is a powerful HTTP server, but in the process of using the discovery, when encountering an extra long post request or get request, Nginx will return 413, 400, 414 Status code, this is because the request string length exceeds the Nginx default cache size or request string size, then we need to how to solve these problems? for a POST request, we can adjust the following two configuration items to resolve:
client_body_buffer_sizesyntax: client_body_buffer_size the_sizedefault value: 8k/16kusing fields: HTTP, server, locationThis instruction can specify the buffer size used by the connection request. If the connection request exceeds the value specified by the buffer, these requests or partial requests will attempt to write to a temporary file. The default value is two memory paging size value, which may be 8k or 16k depending on the platform

client_max_body_sizesyntax: client_max_body_size sizeDefault value: Client_max_body_size 1musing fields: HTTP, server, locationThis directive specifies the maximum number of individual file bytes allowed to be requested by the client, which appears in the Content-length field of the request header. if the request is greater than the specified value, the client will receive a "Request Entity Too Large" (413) error. Remember that the browser does not know how to display this error.

at the same time for the POST request also need to pay attention to the configuration of the following parameter, if you do not open this option when the request string is larger than the client_body_buffer_size size, you need to manually read the request stored in the disk, It is important to note that the request to disk is a complete request is not greater than the client_body_buffer_size part
Client_body_in_single_bufferSyntax: Client_body_in_single_bufferdefault value: Offusing fields: HTTP, server, location this directive (0.7.58 version) specifies that a full connection request be put into the buffer, which is recommended when using $request_body to reduce the copy operation. If a request cannot be placed into a single buffer, it will be put into disk.

For a GET request, we can fix the request string over-length problem by modifying two additional configurations: Client_header_buffer_size syntax: client_header_buffer_size size default: 1k Use field: HTTP, Server This directive specifies the size of the HTTP header buffer requested by the client in most cases the size of a header request will not be greater than 1k However, if there is a larger cookie from the WAP client it may be greater than 1k,nginx will be allocated to it a larger buffer, This value can be set inside the large_client_header_buffers. Large_client_header_buffers Syntax: large_client_header_buffers number size default: Large_client_header_buffers 4 4k/ 8k using fields: HTTP, server directives specify the maximum number of large header files that the client requests to the buffer, and if a request URI size exceeds this value, the server returns a "request URI too Large" (414), similarly, If the header field of a request is greater than this value, the server returns "Bad Request" (400). The buffers are separate according to the requirements. The default one buffer size is Operating SystemThe size of the paging file, usually 4k or 8k, if a connection request converts the state to keep-alive, the buffer will be freed.

then some people will find it strange, why modify the size of the HTTP header can solve the problem of the GET request string too long, this will be from the HTTP protocol get request, actually get commits, the requested data will be appended to the URL ( is to place the data in the HTTP protocol header).

You see, in fact, the GET request parameter is stored in the HTTP header, so the change header size limit of course can solve the request string too long problem. In addition, to clarify the point,the HTTP protocol does not limit the size of the transmitted data, the HTTP protocol specification does not limit the length of the URL, the length of our daily life is limited by the individual browser or HTTP request tool to do their own.

Nginx How to solve the super long request string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.