HTTP code 400

Source: Internet
Author: User


Due to a recent server exception, nginx access logs contain a large number of requests in the following forms:


 



X23.1x3.21x. XX--[08/Jun/2012: 04: 46: 39 + 0800] "-" 400 0 "-" "-" x23.1x3.21x. XX--[08/Jun/2012: 04: 46: 39 + 0800] "-" 408 0 "-""-"


Every day, such requests account for about 50% of requests.
In PHPCodeThe 400 exception is not defined, so it can be determined that it is not thrown by PHP.



This log is found on the internet for the following reasons:





    1. The request header is too long, especially when there are too many cookies.
    2. Chrome's preconnect technology generates a large number of such logs.
    3. No Host header sent


1. If the request header is too long, you can modify the nginx Request Header parameter to a reasonable value.



Parameters:


 



Client_header_buffer_size 64 K; large_client_header_buffers 4 32 K;


However, in fact, this error is generally not reported because the request headers configured by nginx are generally sufficient.



Unless you have defined a large number of cookies.



2. Chrome preconnect



For chrome reasons, there is an obvious feature: the User-Agent = 'chromi' request before each 400 0 request'



And there is no solution.



3. No Host header sent.



An IP scanning tool is used to scan the IP address of the current machine and generate a request without a host in the header.



The following script can be generated:





 



 


We can accept all IP requests by defining a default_server.


 



Server {Listen 80 default_server; SERVER_NAME _; access_log off; Location/{deny all ;}}





In this way, all IP requests are routed to default_server and logs are disabled.



In this way, the annoying "400 0" will disappear.



Here, the problem is basically solved. But there is another thing to note:



The https server must contain two parameters: ssl_certificate and ssl_certificate_key.


Server {Listen 443 SSL default_server; SERVER_NAME _; ssl_certificate/usr/local/nginx/CONF/SSL/Edward. CRT; ssl_certificate_key/usr/local/nginx/CONF/SSL/Edward. key; access_log off; Location/{deny all ;}}




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.