麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 網站 > Nginx > 正文

Nginx服務器屏蔽與禁止屏蔽網絡爬蟲的方法

2024-08-30 12:30:18
字體:
來源:轉載
供稿:網友

每個網站通常都會遇到很多非搜索引擎的爬蟲,這些爬蟲大部分都是用于內容采集或是初學者所寫,它們和搜索引擎的爬蟲不一樣,沒有頻率控制,往往會消耗大量服務器資源,導致帶寬白白浪費了。

其實Nginx可以非常容易地根據User-Agent過濾請求,我們只需要在需要URL入口位置通過一個簡單的正則表達式就可以過濾不符合要求的爬蟲請求:

location / {  if ($http_user_agent ~* "python|curl|java|wget|httpclient|okhttp") {    return 503;  }  # 其它正常配置  ...}

注意:變量$http_user_agent是一個可以直接在location中引用的Nginx變量。~*表示不區分大小寫的正則匹配,通過python就可以過濾掉80%的Python爬蟲。

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

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對ASPKU武林網的支持。


注:相關教程知識閱讀請移步到服務器教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久久久久久亚洲视频 | 曰韩黄色片 | 国产在线观看免费视频软件 | 日本精品二区 | 看免费5xxaaa毛片 | 亚洲精品v天堂中文字幕 | 午夜色视频在线观看 | 天天鲁在线视频免费观看 | 亚洲精品v天堂中文字幕 | 久久久久一区二区三区四区五区 | 欧美亚洲综合网 | 福利在线播放 | 精品一区二区久久久久 | 国产一级免费在线视频 | 久久综合狠狠综合久久 | 欧美一级黄色录像片 | 一区二区精品视频 | 久久亚洲精品久久国产一区二区 | 久久99国产精品久久99 | 国产成人高潮免费观看精品 | 精品国产99久久久久久宅男i | 一级做a爱片性色毛片 | 成人羞羞视频在线观看 | 天天黄色片| 日本xxxx视频 | 精品国产一区二区三区四区阿崩 | 亚洲精品在线观看免费 | 精品国产99久久久久久宅男i | 色播视频网站 | 成人在线视频免费观看 | 性少妇freeseⅹbbwhd| 国产亚洲高清在线精品不卡 | 精品国产一区二区三区在线 | 精品国产一区二区三区天美传媒 | 91精品国产91热久久久做人人 | 一本精品999爽爽久久久 | 成人免费福利网站 | hdjapanesemassagehd日本 | 久久精品视频16 | 亚洲精品午夜国产va久久成人 | 护士hd欧美free性xxxx |