nginx 配置禁止电脑pc访问,禁止抓取

#禁止pc访问,curl定时任务,https://tool.lu/useragent 添加白名单浏览器版本号
set $mobile_request '0';

if ($http_user_agent ~* (curl|Android|iPhone|iPad|Chrome/109.0.0.0)) {

set $mobile_request '1';
}

if ( $request_uri ~* (error)) {

set $mobile_request '2';
}

if ($mobile_request = '0') {
#rewrite ^.+ http://www.baidu.com/error.html;
return 403;
}

#禁止Scrapy等工具的抓取,需要采集用到Curl
#if ($http_user_agent ~ (Scrapy|Curl|HttpClient)) {
if ($http_user_agent ~ (Scrapy|HttpClient)) {
return 403;
}

#禁止指定UA及UA为空的访问
if ($http_user_agent ~ "YandexBot|Bytespider|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|Ezooms|^$" ) {
return 403;
}
#禁止非GET|HEAD|POST方式的抓取
if ($request_method !~ ^(GET|HEAD|POST)$) {
return 403;
}

版权声明:
作者:wanghaha
链接:http://www.aiii.vip/2265.html
来源:我的生活分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>