六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 771|回复: 0

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

[复制链接]
 楼主| 发表于 2015-2-6 11:23:24 | 显示全部楼层 |阅读模式
Nginx限制搜索引擎爬虫频率、禁止屏蔽网络爬虫配置示例
这篇文章主要介绍了Nginx限制搜索引擎爬虫频率、禁止屏蔽网络爬虫配置示例,限制爬虫频率用于一些无良爬虫,禁止爬虫用于一些不需要收录的网站,需要的朋友可以参考下
  1. #全局配置
  2. limit_req_zone $anti_spider zone=anti_spider:10m rate=15r/m;

  3. #某个server中
  4. limit_req zone=anti_spider burst=30 nodelay;
  5. if ($http_user_agent ~* "xxspider|xxbot") {
  6. set $anti_spider $http_user_agent;
  7. }
复制代码
超过设置的限定频率,就会给spider一个503。
上述配置详细解释请自行google下,具体的spider/bot名称请自定义。
附:nginx中禁止屏蔽网络爬虫
  1. server {
  2.         listen       80;
  3.         server_name  www.xxx.com;

  4.         #charset koi8-r;

  5.         #access_log  logs/host.access.log  main;

  6.         #location / {
  7.         #    root   html;
  8.         #    index  index.html index.htm;
  9.         #}
  10.     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") {
  11.                 return 403;
  12.         }

  13.     location ~ ^/(.*)$ {
  14.                 proxy_pass http://localhost:8080;
  15.         proxy_redirect          off;
  16.         proxy_set_header        Host $host;
  17.         proxy_set_header        X-Real-IP $remote_addr;
  18.         proxy_set_header       X-Forwarded-For   $proxy_add_x_forwarded_for;
  19.         client_max_body_size    10m;
  20.         client_body_buffer_size 128k;
  21.         proxy_connect_timeout   90;
  22.         proxy_send_timeout      90;
  23.         proxy_read_timeout      90;
  24.         proxy_buffer_size       4k;
  25.         proxy_buffers           4 32k;
  26.         proxy_busy_buffers_size 64k;
  27.         proxy_temp_file_write_size 64k;
  28.     }
  29.      
  30.         #error_page  404              /404.html;

  31.         # redirect server error pages to the static page /50x.html
  32.         #
  33.         error_page   500 502 503 504  /50x.html;
  34.         location = /50x.html {
  35.             root   html;
  36.         }

  37.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  38.         #
  39.         #location ~ \.php$ {
  40.         #    proxy_pass   http://127.0.0.1;
  41.         #}

  42.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  43.         #
  44.         #location ~ \.php$ {
  45.         #    root           html;
  46.         #    fastcgi_pass   127.0.0.1:9000;
  47.         #    fastcgi_index  index.php;
  48.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
  49.         #    include        fastcgi_params;
  50.         #}

  51.         # deny access to .htaccess files, if Apache's document root
  52.         # concurs with nginx's one
  53.         #
  54.         #location ~ /\.ht {
  55.         #    deny  all;
  56.         #}
  57.     }  
复制代码
可以用 curl 测试一下
  1. curl -I -A "qihoobot" www.xxx.com
复制代码
Nginx限制搜索引擎爬虫频率、禁止屏蔽网络爬虫配置示例
摘自:http://www.jb51.net/article/52569.htm
该会员没有填写今日想说内容.
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表