無效爬蟲、垃圾蜘蛛的阻擋方法

我發現當紅俱樂部有許多爬蟲的 log ,於是蒐集了一些無效爬蟲,以及阻擋方法。

無效的爬蟲又有人稱之為「垃圾蜘蛛」,這些爬蟲機器人大多是 SEO 優化公司,或是沒有價值的爬蟲機器人,會毫無節制的訪問你的網站,造成網站 loading 遽增。滿惱人的,效能來說是還好,但是產生一大堆 access.log ,資料在查找上頗令人不耐。

處理方式有兩個方向:

  1. 當作是壓力測試,想辦法優化網站效能。
  2. 阻擋這些爬蟲的「攻擊」。

以下列出阻擋的方法,這邊主要是使用 useragent 來判斷,在 nginx 中設定阻擋。其中有一個 python 的 useragent ,如果自身有使用 python 處理 curl 等動作的話,要記得排除:

if ($http_user_agent ~* (SemrushBot|python|MJ12bot|AhrefsBot|hubspot|opensiteexplorer|leiki|webmeup|DotBot|petalbot)) {
return 400;
}

另外針對爬蟲設定 rotbot.txt :

User-agent: SemrushBot
Disallow: /

User-agent: python
Disallow: /

User-agent: MJ12bot
Disallow: /

User-agent: AhrefsBot
Disallow: /

User-agent: hubspot
Disallow: /

User-agent: opensiteexplorer
Disallow: /

User-agent: leiki
Disallow: /

User-agent: webmeup
Disallow: /

User-agent: DotBot
Disallow: /

User-agent: petalbot
Disallow: /

不過這個檔案的設定就要看爬蟲本身是否尊重該設定了。


已發佈

分類:

作者: