Upload large files, appear: 413 request Entity too large wrong solution __ work Problem Solving

Source: Internet
Author: User
Tags temporary file storage

Work met a problem, is to upload a 100M file, will report 413 request Entity too large error, the following gives the solution.

After troubleshooting, it was found that the server used Nginx as a reverse proxy server with a name error because the request length exceeded the Nginx default cache size and maximum client maximum request size.

After searching on the internet, we found a solution for post and get mode respectively.for PostFor POST request resolution:
Modify several of the related configuration parameters inside the nginx.conf
Client_body_buffer_size 10m (config request body buffer size, not worthy)
Client_max_body_size 20m (Set client request body maximum)
Client_body_temp_path/data/temp (sets the temporary file storage path.) Only when the uploaded request body exceeds the buffer size will it be written to the temporary file, note that the temporary path must have write permission.
If the upload file size exceeds client_max_body_size, the 413 entity too large error will be reported.
for getFor GET requests, we can solve the problem of long request strings by modifying two other configurations:
Client_header_buffer_size syntax: Client_header_buffer_size size Default value: 1k Using fields: HTTP, server This directive specifies the HTTP header buffer size requested by the client in most cases the size of a header request will not be greater than 1k but if there is a larger cookie from the WAP client it may be greater than 1k,nginx will assign it a larger buffer, this value can be in the Large_ Client_header_buffers inside set. Large_client_header_buffers Syntax: large_client_header_buffers number Size default value: Large_client_header_buffers 4 4k/8k Using fields: HTTP, the server directive specifies the maximum number of larger header files requested by the client to the buffer, and if the URI size of a request exceeds this value, the server returns a "request URI too Large" (414), likewise, If the header field for a request is greater than this value, the server returns "Bad Request" (400). The buffer zone is separated according to the different requirements. The default buffer size is the paging file size in the operating system, usually 4k or 8k, and the buffer will be freed if a connection request converts the state to keep-alive.
Why modifying the size of the HTTP header solves the problem of too long a GET request string. Because the GET request parameters are spelled in the HTTP header, the size of the HTTP header is modified to solve the problem above.
Nginx 400 Error: HTTP header/cookie too largeThe nginx400 error is due to the request header being too large, which is usually caused by a longer string written in the cookie.
The solution is not to record too much data in a cookie, and consider adjusting the client_header_buffer_size (default 1k) in nginx.conf if you really need to.
If the cookie is too large, you may also need to adjust the Large_client_header_buffers (default 4k), which is described below:
If the request line exceeds buffer, it will report an HTTP 414 error (URI Too Long)
Nginx accept the longest HTTP header size must be larger than one of the buffer, or you will report a 400 HTTP error (bad Request).



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.