好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > Nginx服務器屏蔽與禁止屏蔽網(wǎng)絡爬蟲的方法

Nginx服務器屏蔽與禁止屏蔽網(wǎng)絡爬蟲的方法

熱門標簽:遼寧電銷平臺外呼系統(tǒng)軟件 菏澤crm外呼系統(tǒng)價格 物超所值的400電話申請 百應電銷機器人靠譜嗎 信陽銷售外呼系統(tǒng)招商 營銷電銷機器人招商 申請400電話號碼多少錢 如何在各種地圖標注自己的地址 coreldraw地圖標注

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

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

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

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

Nginx中禁止屏蔽網(wǎng)絡爬蟲

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

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關內容請查看下面相關鏈接

標簽:玉樹 湖北 廈門 江門 江西 內江 泰安 瀘州

巨人網(wǎng)絡通訊聲明:本文標題《Nginx服務器屏蔽與禁止屏蔽網(wǎng)絡爬蟲的方法》,本文關鍵詞  Nginx,服務器,屏蔽,與,禁止,;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Nginx服務器屏蔽與禁止屏蔽網(wǎng)絡爬蟲的方法》相關的同類信息!
  • 本頁收集關于Nginx服務器屏蔽與禁止屏蔽網(wǎng)絡爬蟲的方法的相關信息資訊供網(wǎng)民參考!
  • 推薦文章