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:
- The request header is too long, especially when there are too many cookies.
- Chrome's preconnect technology generates a large number of such logs.
- 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 ;}}