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;
}
共有 0 条评论