Causes and Solutions for nginx 400 Bad request errors

Source: Internet
Author: User

Fortunately, there is a way to solve this problem in nginx:

In nginx. conf, increase the values of client_header_buffer_size and large_client_header_buffers to alleviate this problem.

Client_header_buffer_size: The default value is 1 k. Therefore, if the header is smaller than 1 k, no problem will occur.
Large_client_header_buffers: this command is used to set the size of the Header buffer for client requests. The default value is 4 kB. The client Request line cannot exceed the value set by the large_client_header_buffers command. The Header information of the client Request cannot exceed the buffer size set by the large_client_header_buffers command. Otherwise, the Request URL too large (414) is reported) or "Bad-request" (400) error. If the client Cookie information is large, the buffer size must be increased.

The configuration is as follows:

The code is as follows: Copy code

Client_header_buffer_size 128 k;

Large_client_header_buffers 4 128 k;


Remove the 400 method from the access log

Nginx versions earlier than 0.7.12 receive an empty request. nginx does not match any virtual host and returns error 400 directly,

Later versions of nginx can use server_name _; to match empty request headers.

Therefore, if you use an earlier version, upgrade it to version 0.7.12 or later.

After the upgrade, add the following default virtual host server.

Add the default server to the configuration file. The following configuration explanation shows that unauthorized access to the domain name is prohibited.

The code is as follows: Copy code

Server {
Listen 80 default_server;
Server_name _;
Return 404;
Access_log off;
}

We recommend that you save the server as default. conf and include it to the main configuration file nginx. conf.

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.