Nginx访问日志中UserAgent的一些参考建议

By Heanny
2020-05-01
2471 read

前言

网络上存在各种各样的爬虫与蜘蛛,有的是对网站有帮助的,譬如说:百度(Baiduspider)、谷歌(Googlebot)、Bing(bingbot)等等,但是也有一些纯粹是垃圾爬虫,不但本身对网站毫无帮助,还大幅损耗服务器资源,如:BLEXBot、AhrefsBot、MJ12bot、hubspot、opensiteexplorer、leiki、webmeup 等,所以我们可以通过UserAgent信息来屏蔽垃圾爬虫

nginx配置

将指定的userAgent返回403

if($http_user_agent ~* 'curl|python-requests|urllib|Baiduspider|YisouSpider|Google|Sogou|bingbot|python|AndroidDownloadManager|ZoominfoBot|SemrushBot|AhrefsBot|Java|Jullo|UniversalFeedParser|Swiftbot|Microsoft|oBot|FlightDeckReports|Linguee|DotBot|Indy|jaunty|HttpClient|WinHttp|ZmEu|ApacheBench|CrawlDaddy|BOT for JCE')
{
return 	403;
}

# 如果多个server都设置,建议使用map
# 禁止的user agent
map $http_user_agent $ban_ua {
    default '';
    '~*MJ12bot|curl|NetcraftSurvey|Go-http-client|polaris botnet|python-requests|urllib|Scrapy|Baiduspider|YisouSpider|Google|Sogou|bingbot|python|AndroidDownloadManager|ZoominfoBot|SemrushBot|AhrefsBot|Java|Jullo|UniversalFeedParser|Swiftbot|Microsoft|oBot|FlightDeckReports|Linguee|DotBot|Indy|jaunty|HttpClient|WinHttp|ZmEu|ApacheBench|CrawlDaddy|BOT for JCE'  'error';
}
if ($ban_ua){
    return 403;
}

推荐允许

搜索引擎类

常见的搜索引擎的可以推荐,利于收录,一般都遵循robots.txt协议

  • 百度:BaiduSpider,
  • Google:Googlebot,
  • 360:360Spider,
  • Bing:bingbot,
  • 搜搜:Sosospider,

订阅类

  • RSS订阅采集:FeedDemon,Feedly

禁止类-数据采集

该分类下的爬虫对网站帮助不大,可能会暴力爬取页面,流氓的有的还不遵循robots.txt协议

  • ZoominfoBot 是一个北美为主的数据网站,用来搜寻北美公司曾经出现在网页上的邮箱
  • MJ12bot 暴力蜘蛛
  • SemrushBot 提供SEO数据的平台,包括关键字研究和反向链接。
  • AhrefsBot 国外营销爬虫,无用爬虫。
  • Java 内容采集
  • Jullo 内容采集
  • UniversalFeedParser 内容采集
  • Swiftbot 无用爬虫
  • Microsoft URL Control ;扫描
  • oBot 无用爬虫
  • Python-urllib 内容采集
  • FlightDeckReports Bot 无用爬虫
  • Linguee Bot 无用爬虫
  • DotBot 无用爬虫
  • BLEXBot 美国查反链的工具网站
  • opensiteexplorer 国外seo工具网站
  • hubspot国外企业营销
  • MJ12bot英国搜索引擎
  • yandex俄罗斯搜索引擎
  • zmeu漏洞扫描软件
  • polaris botnet僵尸网络
  • NetcraftSurvey垃圾

rebots.txt配置

  • User-agent: Baiduspider
  • Allow: /
  • User-agent: Baiduspider-image
  • Allow: /
  • User-agent: ;Baiduspider-video
  • Allow: /
  • User-agent: Baiduspider-news
  • Allow: /
  • User-agent: Googlebot
  • Allow: /
  • User-agent: MSNBot
  • Allow: /
  • User-agent: MJ12bot
  • Disallow: /
【树莓派】centos系统扩展tf剩余空间
【直播】使用python控制b站直播视频

Comments

暂无评论,还不快来坐沙发...

Leave a Reply