nginx 反爬虫设置

在server块加入如下设置:

#禁止Scrapy等工具的抓取  

if ($http_user_agent ~* (Scrapy|python|Curl|java|wget|HttpClient|okhttp)) {  

     return 404;  

}


#禁止指定UA及UA为空的访问  

if ($http_user_agent ~ "WinHttp|WebZIP|FetchURL|node-superagent|java/|FeedDemon|Jullo|JikeSpider|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|Java|Feedly|Apache-HttpAsyncClient|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|HttpClient|MJ12bot|heritrix|EasouSpider|Ezooms|BOT/0.1|YandexBot|FlightDeckReports|Linguee Bot|^$" ) {  

     return 404;               

}

#禁止非GET|HEAD|POST方式的抓取  

if ($request_method !~ ^(GET|HEAD|POST)$) {  

    return 404;  

}


该文章对你有帮助吗,求分享转发: 分享到QQ空间 分享给QQ好友

 

 

粤ICP备19116230号
友情链接: 码农藏书阁 天天链