zoukankan      html  css  js  c++  java
  • Nginx禁止蜘蛛爬取服务器

    修改nginx.conf,禁止网络爬虫的ua,返回403

    添加agent_deny.conf配置文件

    #禁止Scrapy等工具的抓取
    if ($http_user_agent ~* (Scrapy|Curl|HttpClient)) {
      return 403;
    }
    #禁止指定UA及UA为空的访问
    if ($http_user_agent ~ "FeedDemon|JikeSpider|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|YisouSpider|HttpClient|MJ12bot|heritrix|EasouSpider|LinkpadBot|Ezooms|^$" )
    {
      return 403;
    }
    #禁止非GET|HEAD|POST方式的抓取
    if ($request_method !~ ^(GET|HEAD|POST)$) {
      return 403;
    }

    在网站相关配置文件中插入代码“include agent_deny.conf ;”。

    location ~ [^/].php(/|$)
    {
      try_files $uri =404;
      fastcgi_pass  unix:/tmp/php-cgi.sock;
      fastcgi_index index.php;
      include fastcgi.conf;
      include agent_deny.conf;
    }
     

    重新加载nginx

    /etc/init.d/nginx reload

    另外从apache中直接禁掉所有蜘蛛的抓取可以用以下配置

    BrowserMatch "Spider" bad_bot

  • 相关阅读:
    第一次通过CLR Profile解决内存占用过高的问题
    未处理的异常
    var和dynamic的区别及如何正确使用dynamic?
    C#添加本地打印机
    CSS样式
    CSS选择器
    Winform 数据绑定
    [CLR via C#]值类型的装箱和拆箱
    Java Object
    设计模式_创建型模式
  • 原文地址:https://www.cnblogs.com/enumx/p/12299956.html
Copyright © 2011-2022 走看看