如何用nginx限制屏蔽恶意搜索引擎爬虫禁止抓取网站?
系统运维
48 人阅读
|
1 人回复
|
2024-05-05
|
本帖最后由 求知者 于 2024-5-5 15:56 编辑
如何用nginx限制屏蔽搜索引擎爬虫访问,禁止蜘蛛抓取网站?
|
|
|
|
|
|
|
大神
发表于 2024-5-5 18:13:54
|
显示全部楼层
一般修改nginx.conf文件,
宝塔面板路径:panel/vhost/nginx/www.dadu.xyz.conf(www.dadu.xyz为自己的网站,请自行修改)
- #禁止Scrapy等爬虫工具的抓取
- if ($http_user_agent ~* "Scrapy|Sogou web spider|Baiduspider") {
- 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|LinkpadBot|Ezooms|^$" )
- {
- return 403;
- }
- #禁止非GET|HEAD|POST方式的抓取
- if ($request_method !~ ^(GET|HEAD|POST)$) {
- return 403;
- }
复制代码
没有人用的低版本配置(一般是伪装成真实用户)
- if ($http_user_agent ~ "Mozilla/4.0\ \(compatible;\ MSIE\ 6.0;\ Windows\ NT\ 5.1;\ SV1;\ .NET\ CLR\ 1.1.4322;\ .NET\ CLR\ 2.0.50727\)") {
- return 404;
- }
复制代码
相关教程:
【大全】恶意User-Agent过滤列表Nginx/Apache屏蔽蜘蛛爬虫
|
|
|
|
|
|