新建配置配置文件 (例如进入到nginx装置目录下的conf目录,创立: agent_deny.conf)
禁止Scrapy等工具的抓取 if ($http_user_agent ~* (Scrapy|Curl|HttpClient)) { return 403; }
- 禁止指定UA及UA为空的拜访
#forbidden Scrapy
if ($http_user_agent ~* (Scrapy|Curl|HttpClient))
{
return 403;
}
#forbidden UA
if ($http_user_agent ~ "Bytespider|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;
}
#forbidden not GET|HEAD|POST method access
if ($request_method !~ ^(GET|HEAD|POST)$)
{
return 403;
}
而后,在网站相干配置中的 server段插入如下代码: include agent_deny.conf;
重启nginx:
- /data/nginx/sbin/nginx -s reload
测试 应用curl -A 模仿抓取即可,比方:
- curl -I -A ‘YYSpider’ <<<www.xxx.con>>>
后果
[root@11 conf]# curl -I -A 'YYSpider' www.xxx.cn
HTTP/1.1 403 Forbidden
Server: nginx/1.12.0
Date: Wed, 24 Apr 2019 11:35:21 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
模仿UA为空的抓取:
- curl -I -A’ ‘ <<<www.xxx.cn>>>
后果
[root@11 conf]# curl -I -A' ' www.xxx.cn
HTTP/1.1 403 Forbidden
Server: nginx/1.12.0
Date: Wed, 24 Apr 2019 11:36:06 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
模仿百度蜘蛛的抓取:
- curl -I -A ‘Baiduspider’ <<<www.xxx.cn>>>
[root@11 conf]# curl -I -A 'Baiduspider' www.xxx.cn
HTTP/1.1 200 OK
Server: nginx/1.12.0
Date: Wed, 24 Apr 2019 11:36:47 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Fri, 12 Apr 2019 13:49:36 GMT
Connection: keep-alive
ETag: "5cb09770-264"
Accept-Ranges: bytes
UA类型
FeedDemon 内容采集
BOT/0.1 (BOT for JCE) sql注入
CrawlDaddy sql注入
Java 内容采集
Jullo 内容采集
Feedly 内容采集
UniversalFeedParser 内容采集
ApacheBench cc攻击器
Swiftbot 无用爬虫
YandexBot 无用爬虫
AhrefsBot 无用爬虫
YisouSpider 无用爬虫(已被UC神马搜寻收买,此蜘蛛能够放开!)
jikeSpider 无用爬虫
MJ12bot 无用爬虫
ZmEu phpmyadmin 破绽扫描
WinHttp 采集cc攻打
EasouSpider 无用爬虫
HttpClient tcp攻打
Microsoft URL Control 扫描
YYSpider 无用爬虫
jaunty wordpress爆破扫描器
oBot 无用爬虫
Python-urllib 内容采集
Indy Library 扫描
FlightDeckReports Bot 无用爬虫
Linguee Bot 无用爬虫
nginx 防盗链配置
背景:避免第三方援用链接拜访咱们的图片,耗费服务器资源和网络流量,咱们能够在服务器上做防盗链限度。
实现防盗链的形式有两种:refer形式和签名形式。
refer形式实现防盗链
工作模块:ngx_http_referer_module。
作用变量:$invalid_referer,全局变量。
配置域:server, location
配置:
server {
listen 80;
server_name www.imcati.com refer-test.imcati.com;
root /usr/share/nginx/html;
location ~*\.(gif|jpg|jpeg|png|bmp|swf)$ {
valid_referers none blocked www.imcati.com;
if ($invalid_referer) {
return 403;
}
}
}
- valid_referers: 指定资源拜访是通过以下几种形式为非法,即白名单。 vaild_referers 无效的援用连贯,如下,否则就进入$invaild_refere,返回403 forbiden。
- none:容许缺失的头部拜访。
- blocked:容许referer没有对应值的申请。
- server_names:若referer站点域名与server_name中本机配的域名一样容许拜访。
发表回复