跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • nginx禁止某些User Agent抓取网站
未分類
9 5 月 2020

nginx禁止某些User Agent抓取网站

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防火墙不错。。

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具