gnocuil 大佬有话说 :
nginx禁止某些User Agent抓取网站
参考的这篇文章https://zhang.ge/4458.htm
宝塔nginx 1.4报错,求指导
nginx: "if" directive is not allowed here in /www/server/nginx/conf/agent_deny.conf:2
nginx: configuration file /www/server/nginx/conf/nginx.conf test failed
agent_deny.conf:内容如下
#禁止Scrapy等工具的抓取
if ($http_user_agent ~* (Scrapy|Curl|HttpClient)) {
return 403;
}
#禁止指定UA及UA为空的访问
if ($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|Ezooms|^$" ) {
return 403;
}
#禁止非GET|HEAD|POST方式的抓取
if ($request_method !~ ^(GET|HEAD|POST)$) {
return 403;
}
hanada 大佬有话说 :
你试试放在location / 里头:lol
https://cdn.jsdelivr.net/gh/hishis/forum-master/public/images/patch.gif
gnocuil 大佬有话说 :
hanada 大佬有话说 : 2020-5-9 17:25
你试试放在location / 里头
一样也报错。
iks 大佬有话说 :
中间有空格,得用 /s 代替
tir 大佬有话说 :
多谢分享,不过百度有
GoogleCloud 大佬有话说 :
宝塔那个nginx防火墙不错。。