Nginx限制搜索引擎爬虫频率、禁止屏蔽网络爬虫配置示例

 更新时间:2014年07月23日 08:37:31   投稿:junjie  
这篇文章主要介绍了Nginx限制搜索引擎爬虫频率、禁止屏蔽网络爬虫配置示例,限制爬虫频率用于一些无良爬虫,禁止爬虫用于一些不需要收录的网站,需要的朋友可以参考下

复制代码 代码如下:

#全局配置
limit_req_zone $anti_spider zone=anti_spider:10m rate=15r/m;

#某个server中
 limit_req zone=anti_spider burst=30 nodelay;
 if ($http_user_agent ~* "xxspider|xxbot") {
 set $anti_spider $http_user_agent;
}

超过设置的限定频率,就会给spider一个503。
上述配置详细解释请自行google下,具体的spider/bot名称请自定义。

附:nginx中禁止屏蔽网络爬虫

复制代码 代码如下:

server { 
        listen       80; 
        server_name  www.xxx.com; 
 
        #charset koi8-r; 
 
        #access_log  logs/host.access.log  main; 
 
        #location / { 
        #    root   html; 
        #    index  index.html index.htm; 
        #} 
    if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot") { 
                return 403; 
        } 
 
    location ~ ^/(.*)$ { 
                proxy_pass http://localhost:8080; 
        proxy_redirect          off; 
        proxy_set_header        Host $host; 
        proxy_set_header        X-Real-IP $remote_addr; 
        proxy_set_header       X-Forwarded-For   $proxy_add_x_forwarded_for; 
        client_max_body_size    10m; 
        client_body_buffer_size 128k; 
        proxy_connect_timeout   90; 
        proxy_send_timeout      90; 
        proxy_read_timeout      90; 
        proxy_buffer_size       4k; 
        proxy_buffers           4 32k; 
        proxy_busy_buffers_size 64k; 
        proxy_temp_file_write_size 64k; 
    } 
     
        #error_page  404              /404.html; 
 
        # redirect server error pages to the static page /50x.html 
        # 
        error_page   500 502 503 504  /50x.html; 
        location = /50x.html { 
            root   html; 
        } 
 
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
        # 
        #location ~ \.php$ { 
        #    proxy_pass   http://127.0.0.1; 
        #} 
 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
        # 
        #location ~ \.php$ { 
        #    root           html; 
        #    fastcgi_pass   127.0.0.1:9000; 
        #    fastcgi_index  index.php; 
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name; 
        #    include        fastcgi_params; 
        #} 
 
        # deny access to .htaccess files, if Apache's document root 
        # concurs with nginx's one 
        # 
        #location ~ /\.ht { 
        #    deny  all; 
        #} 
    } 


可以用 curl 测试一下

复制代码 代码如下:
curl -I -A "qihoobot" www.xxx.com

相关文章

  • Linux部署Nginx实现反向代理的方法步骤

    Linux部署Nginx实现反向代理的方法步骤

    Nginx 是一种常用、轻型且快速的 Web 服务器, 它可以在 Linux 和 Windows 上运行,并且可以配置为反向代理服务器,本文主要介绍了Linux部署Nginx实现反向代理的方法步骤,感兴趣的可以了解一下
    2023-08-08
  • nginx里集成php模块安装配置步骤详解

    nginx里集成php模块安装配置步骤详解

    这篇文章主要为大家介绍了nginx里集成php模块安装配置步骤详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-08-08
  • Nginx四层负载均衡的实现示例

    Nginx四层负载均衡的实现示例

    Nginx 不支持传统的四层负载均衡,但可以通过stream模块配合TCP实现类似的功能,本文主要介绍了Nginx四层负载均衡的实现示例,具有一定的参考价值,感兴趣的可以了解一下
    2024-04-04
  • 如何实现Nginx同一端口同时支持http与https协议

    如何实现Nginx同一端口同时支持http与https协议

    最近有一个需求,需要让一个端口的http服务支持https访问,本文就来介绍一下如何实现Nginx同一端口同时支持http与https协议,感兴趣的可以了解一下
    2023-11-11
  • Nginx的流式响应配置实现小结

    Nginx的流式响应配置实现小结

    nginx是一款自由的、开源的、高性能的HTTP服务器和反向代理服务器,本文主要介绍了Nginx的流式响应配置实现小结,具有一定的参考价值,感兴趣的可以了解一下
    2024-04-04
  • Nginx配置文件nginx.conf的基本配置实例详解

    Nginx配置文件nginx.conf的基本配置实例详解

    Nginx(engine x)是一个轻量级的高性能的HTTP和反向代理web服务器及电子邮件(IMAP/POP3)代理服务器,下面这篇文章主要给大家介绍了关于Nginx配置文件nginx.conf基本配置的相关资料,需要的朋友可以参考下
    2022-09-09
  • 详解nginx websocket配置

    详解nginx websocket配置

    这篇文章主要介绍了详解nginx websocket配置,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-08-08
  • Nginx PHP-Fcgi中因PHP执行时间导致504 Gateway Timeout错误解决记录

    Nginx PHP-Fcgi中因PHP执行时间导致504 Gateway Timeout错误解决记录

    这篇文章主要介绍了Nginx PHP-Fcgi中因PHP执行时间导致504 Gateway Timeout错误解决记录,本文的解决方法得来不易,需要的朋友可以参考下
    2014-09-09
  • Nginx反向代理proxy_cache_path directive is not allowed错误解决方法

    Nginx反向代理proxy_cache_path directive is not allowed错误解决方法

    这篇文章主要介绍了Nginx反向代理proxy_cache_path directive is not allowed错误解决方法,需要的朋友可以参考下
    2015-04-04
  • windows系统安装配置nginx环境

    windows系统安装配置nginx环境

    这篇文章介绍了windows系统安装配置nginx环境的方法,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-06-06

最新评论