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.