我们都知道网络上的爬虫非常多,有对网站收录有益的,比如百度蜘蛛(Baiduspider),也有不但不遵守 robots 规则对服务器造成压力,还不能为网站带来流量的无用爬虫,比如宜搜蜘蛛(YisouSpider)最新补充:宜搜蜘蛛已被 UC 神马搜索收购!所以本文已去掉宜搜蜘蛛的禁封!)。最近,服务器被垃圾爬虫导致频繁卡死,实在忍无可忍了,于是整理收集了网络上各种禁止垃圾蜘蛛爬站的方法,在给自己网做设置的同时,也给各位站长提供参考。

一、Apache

①、通过修改 .htaccess 文件

修改网站目录下的.htaccess,添加如下代码即可(2 种代码任选):

可用代码 (1):




RewriteEngine OnRewriteCond %{HTTP_USER_AGENT} (^$|FeedDemon|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|HttpClient|MJ12bot|heritrix|EasouSpider|DotBot|Ezooms) [NC]RewriteRule ^(.*)$ - [F]
 可用代码 (2):
SetEnvIfNoCase ^User-Agent$ .*(FeedDemon|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|HttpClient|MJ12bot|heritrix|EasouSpider|DotBot|Ezooms) BADBOTOrder Allow,DenyAllow from allDeny from env=BADBOT

可用代码(3)

如果以上两种方式会导致500错误,可以使用下面的代码。

setEnvIfNoCase User-Agent "^$" bad_botsetEnvIfNoCase User-Agent "^FeedDemon" bad_botsetEnvIfNoCase User-Agent "^Indy Library" bad_botsetEnvIfNoCase User-Agent "^Alex Toolbar" bad_botsetEnvIfNoCase User-Agent "^AskTbFXTV" bad_botsetEnvIfNoCase User-Agent "^AhrefsBot" bad_botsetEnvIfNoCase User-Agent "^CrawlDaddy" bad_botsetEnvIfNoCase User-Agent "^CoolpadWebkit" bad_botsetEnvIfNoCase User-Agent "^Java" bad_botsetEnvIfNoCase User-Agent "^Feedly" bad_botsetEnvIfNoCase User-Agent "^UniversalFeedParser" bad_botsetEnvIfNoCase User-Agent "^ApacheBench" bad_botsetEnvIfNoCase User-Agent "^Microsoft URL Control" bad_botsetEnvIfNoCase User-Agent "^Swiftbot" bad_botsetEnvIfNoCase User-Agent "^ZmEu" bad_botsetEnvIfNoCase User-Agent "^oBot" bad_botsetEnvIfNoCase User-Agent "^jaunty" bad_botsetEnvIfNoCase User-Agent "^Python-urllib" bad_botsetEnvIfNoCase User-Agent "^lightDeckReports Bot" bad_botsetEnvIfNoCase User-Agent "^YYSpider" bad_botsetEnvIfNoCase User-Agent "^DigExt" bad_botsetEnvIfNoCase User-Agent "^HttpClient" bad_botsetEnvIfNoCase User-Agent "^MJ12bot" bad_botsetEnvIfNoCase User-Agent "^heritrix" bad_botsetEnvIfNoCase User-Agent "^EasouSpider" bad_botsetEnvIfNoCase User-Agent "^DotBot" bad_botsetEnvIfNoCase User-Agent "^Ezooms" bad_botDeny from env=bad_bot

其它方法见以下文章,一般前面三种代码就可以解决问题,本站是第三种代码解决,前面两种导致500错误。

https://qdmana.com/2021/10/20211007175205904u.html

发表回复

后才能评论