暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

服务器反爬虫攻略:nginx禁止某些User Agent抓取网站

DevOps架构实战 2021-01-08
2517

下面介绍怎么禁止这些无用的user agent访问网站。


进入到nginx安装目录下的conf目录,将如下代码保存为 agent_deny.conf

cd usr/local/nginx/conf

vim agent_deny.conf



1

2

3

4

5

6

7

8

9

10

11

12

#禁止Scrapy等工具的抓取

if ($http_user_agent ~* (Scrapy|Curl|HttpClient)) {

return 403;

}

#禁止指定UA及UA为空的访问

if ($http_user_agent ~ "FeedDemon|JikeSpider|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|CoolpadWebkit|Java|Feedly|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|YisouSpider|HttpClient|MJ12bot|heritrix|EasouSpider|Ezooms|^$" ) {

return 403;

}

#禁止非GET|HEAD|POST方式的抓取

if ($request_method !~ ^(GET|HEAD|POST)$) {

return 403;

}


然后,在网站相关配置中的 location / { 之后插入如下代码:

include agent_deny.conf;


保存后,执行如下命令,平滑重启nginx即可:

/usr/local/nginx/sbin/nginx -s reload


模拟宜搜蜘蛛的抓取:

curl -I -A 'YisouSpider' http://网站链接

结果返回403


模拟UA为空的抓取:

curl -I -A '' http://网站链接

结果返回403


模拟百度蜘蛛的抓取:

curl -I -A 'Baiduspider' http://网站链接

结果返回200


下面是网络上常见的垃圾UA列表

FeedDemon 内容采集

BOT/0.1 (BOT for JCE) sql注入

CrawlDaddy sql注入

Java 内容采集

Jullo 内容采集

Feedly 内容采集

UniversalFeedParser 内容采集

ApacheBench cc攻击器

Swiftbot 无用爬虫

YandexBot 无用爬虫

AhrefsBot 无用爬虫

YisouSpider 无用爬虫

jikeSpider 无用爬虫

MJ12bot 无用爬虫

ZmEu phpmyadmin 漏洞扫描

WinHttp 采集cc攻击

EasouSpider 无用爬虫

HttpClient tcp攻击

Microsoft URL Control 扫描

YYSpider 无用爬虫

jaunty wordpress爆破扫描器

oBot 无用爬虫

Python-urllib 内容采集

Indy Library 扫描

FlightDeckReports Bot 无用爬虫

Linguee Bot 无用爬虫


文章转载自DevOps架构实战,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论