比如说用了阿里云的slb ,然后他会检测服务器是否正常运行,通常会发大量的HEAD 请求过来。
这样有规则的请求是可以屏蔽的。步骤如下:
- 在 <Directory />中添加 SetEnvIf Request_Method HEAD dontlog
- CustomLog 中修改成 CustomLog logs/access_log combined env=!dontlog
- reload 即可。
可参考http://www.howtoforge.com/setenvif_apache2
官网http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html
不只是Request_Method 还有其他变量也可以进行判断
- Host
- User-Agent
- Referer
- Accept-Language
- Remote_Host: the hostname (if available) of the client making the request.
- Remote_Addr: the IP address of the client making the request.
- Server_Addr: the IP address of the server on which the request was received (only with versions later than 2.0.43).
- Request_Method: the name of the method being used (GET, POST, etc.).
- Request_Protocol: the name and version of the protocol with which the request was made (e.g., "HTTP/0.9", "HTTP/1.1", etc.).
- Request_URI: the resource requested on the HTTP request line - generally the portion of the URL following the scheme and host portion without the query string.
nginx 里面就简单一些
if ( $request_method = "HEAD" )
{
access_log off ;
}