nginx中禁止屏蔽网络爬虫


Xml代码    收藏代码
  1. server {  
  2.         listen       80;  
  3.         server_name  www.xxx.com;  
  4.   
  5.         #charset koi8-r;  
  6.   
  7.         #access_log  logs/host.access.log  main;  
  8.   
  9.         #location / {  
  10.         #    root   html;  
  11.         #    index  index.html index.htm;  
  12.         #}  
  13.     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") {  
  14.                 return 403;  
  15.         }  
  16.   
  17.     location ~ ^/(.*)$ {  
  18.                 proxy_pass http://localhost:8080;  
  19.         proxy_redirect          off;  
  20.         proxy_set_header        Host $host;  
  21.         proxy_set_header        X-Real-IP $remote_addr;  
  22.         proxy_set_header       X-Forwarded-For   $proxy_add_x_forwarded_for;  
  23.         client_max_body_size    10m;  
  24.         client_body_buffer_size 128k;  
  25.         proxy_connect_timeout   90;  
  26.         proxy_send_timeout      90;  
  27.         proxy_read_timeout      90;  
  28.         proxy_buffer_size       4k;  
  29.         proxy_buffers           4 32k;  
  30.         proxy_busy_buffers_size 64k;  
  31.         proxy_temp_file_write_size 64k;  
  32.     }  
  33.       
  34.         #error_page  404              /404.html;  
  35.   
  36.         # redirect server error pages to the static page /50x.html  
  37.         #  
  38.         error_page   500 502 503 504  /50x.html;  
  39.         location = /50x.html {  
  40.             root   html;  
  41.         }  
  42.   
  43.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
  44.         #  
  45.         #location ~ \.php$ {  
  46.         #    proxy_pass   http://127.0.0.1;  
  47.         #}  
  48.   
  49.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
  50.         #  
  51.         #location ~ \.php$ {  
  52.         #    root           html;  
  53.         #    fastcgi_pass   127.0.0.1:9000;  
  54.         #    fastcgi_index  index.php;  
  55.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  
  56.         #    include        fastcgi_params;  
  57.         #}  
  58.   
  59.         # deny access to .htaccess files, if Apache's document root  
  60.         # concurs with nginx's one  
  61.         #  
  62.         #location ~ /\.ht {  
  63.         #    deny  all;  
  64.         #}  
  65.     }  
   可以用 curl 测试一下

curl -I -A "qihoobot" www.xxx.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值