Q:发现有时候,百度抓取非常频繁,会导致服务器压力过大。如何限制他们的抓取频率?
A:
Nginx
的ngx_http_limit_req_module
模块限制了百度蜘蛛的抓取频率。每分钟允许百度蜘蛛抓取200次,多余的抓取请求返回503。
nginx的配置:
首先,在nginx.conf文件中的http模块下配置
limit_req_zone $binary_remote_addr zone=anti_spider:60m rate=200r/m;
说明:区域名称为one(自定义),占用空间大小为60m,平均处理的请求频率不能超过每秒200次。
$binaryremoteaddr是$remoteaddr(客户端IP)的二进制格式,固定占用4个字节(可能是C语言的long类型长度)。而$remoteaddr按照字符串存储,占用7-15个字节。这样看来用$binaryremoteaddr可以节省空间,但网上又说64位系统下都是占用64个字节,没搞清楚,总之尽量用$binaryremoteaddr吧。
某个server中
limit_req zone=anti_spider burst=5 nodelay; if ($http_user_agent ~* "baiduspider") { set $anti_spider $http_user_agent; }
参数说明:
IF部分用于判断是否是百度蜘蛛的user agent。如果是,就对变量$anti_spider赋值。这样就做到了只对百度蜘蛛进行限制了。
stat -c "%a %n" file , 755, 644
ModuleNotFoundError: No module named 'MySQLdb', ...
Ubuntu18.04下使用pyenv安装python报错:BUILD FAILED (Ubun ...
dell提供了工具远程查看服务器硬件状态,可以修改硬件的参数,可以远程连接过去直接修改,就不需要 ...
启动报undefined symbol: EVP_CIPHER_CTX_cleanup错误。op ...
ubuntu开启crontab日志记录及解决No MTA installed, discardi ...
暂时还没有评论,第一个来评论吧!