黑帽联盟

 找回密码
 会员注册
查看: 1313|回复: 0
打印 上一主题 下一主题

[技术文章] nginx限制搜索引擎爬虫频率设置

[复制链接]
yun 黑帽联盟官方人员 

920

主题

37

听众

1364

积分

超级版主

Rank: 8Rank: 8

  • TA的每日心情
    奋斗
    2019-10-18 11:20
  • 签到天数: 678 天

    [LV.9]以坛为家II

    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

    帖子永久地址: 

    黑帽联盟 - 论坛版权1、本主题所有言论和图片纯属会员个人意见,与本论坛立场无关
    2、本站所有主题由该帖子作者发表,该帖子作者与黑帽联盟享有帖子相关版权
    3、其他单位或个人使用、转载或引用本文时必须同时征得该帖子作者和黑帽联盟的同意
    4、帖子作者须承担一切因本文发表而直接或间接导致的民事或刑事法律责任
    5、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
    6、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
    7、黑帽联盟管理员和版主有权不事先通知发贴者而删除本文

    您需要登录后才可以回帖 登录 | 会员注册

    发布主题 !fastreply! 收藏帖子 返回列表 搜索
    回顶部