在網站運維過程中,需明確區分正常搜索引擎蜘蛛與惡意爬蟲的差異。正常蜘蛛(如百度蜘蛛、Googlebot等)對網站收錄及搜索引擎排名至關重要,隨意屏蔽可能導致網站權重下降、流量流失,甚至造成客戶資源損失。若當前服務器資源面臨壓力,建議優先考慮升級虛擬主機套餐以提升流量配額,或遷移至云服務器架構(支持不限流量配置),從硬件層面優化訪問承載能力。更多服務器升級方案可參考:http://www.west.cn/faq/list.asp?unid=626。
針對需要屏蔽特定蜘蛛的場景,需先完成偽靜態組件的配置部署。若使用網站管理助手搭建環境,請參照指南啟用偽靜態組件:http://www.west.cn/faq/list.asp?unid=650;對于Windows Server 2003 + IIS手工建站環境,可參考:http://www.west.cn/faq/list.asp?unid=639 完成組件加載。完成前置配置后,需根據服務器操作系統類型,在對應配置文件中添加屏蔽規則。
Linux環境(Apache/Nginx)
在站點根目錄創建`.htaccess`文件,添加如下規則:
```apache
RewriteEngine On
#Block spider
RewriteCond %{HTTP_USER_AGENT} "SemrushBot|Webdup|AcoonBot|AhrefsBot|Ezooms|EdisterBot|EC2LinkFinder|jikespider|Purebot|MJ12bot|WangIDSpider|WBSearchBot|Wotbox|xbfMozilla|Yottaa|YandexBot|Jorgee|SWEBot|spbot|TurnitinBot-Agent|mail.RU|curl|perl|Python|Wget|Xenu|ZmEu" [NC]
RewriteRule !(^robots\.txt$) - [F]
```
Windows Server 2003 + IIS環境
在`httpd.conf`文件中配置規則:
```apache
#Block spider
RewriteCond %{HTTP_USER_AGENT} (SemrushBot|Webdup|AcoonBot|AhrefsBot|Ezooms|EdisterBot|EC2LinkFinder|jikespider|Purebot|MJ12bot|WangIDSpider|WBSearchBot|Wotbox|xbfMozilla|Yottaa|YandexBot|Jorgee|SWEBot|spbot|TurnitinBot-Agent|mail.RU|curl|perl|Python|Wget|Xenu|ZmEu) [NC]
RewriteRule !(^/robots.txt$) - [F]
```
Windows Server 2008 + IIS環境
在`web.config`文件中添加規則:
```xml
```
Nginx環境
在站點配置文件的`server`段內添加規則:
```nginx
if ($http_user_agent ~ "Bytespider|Java|PhantomJS|SemrushBot|Scrapy|Webdup|AcoonBot|AhrefsBot|Ezooms|EdisterBot|EC2LinkFinder|jikespider|Purebot|MJ12bot|WangIDSpider|WBSearchBot|Wotbox|xbfMozilla|Yottaa|YandexBot|Jorgee|SWEBot|spbot|TurnitinBot-Agent|mail.RU|perl|Python|Wget|Xenu|ZmEu|^$")
{
return 444;
}
```
注:上述規則默認屏蔽部分非必要蜘蛛,如需擴展屏蔽范圍,可根據規則格式添加目標蜘蛛特征標識。
附:常見搜索引擎蜘蛛名稱參考
- Google:googlebot
- 百度:baiduspider、baiduboxapp(移動端)
- Yahoo:slurp
- Alexa:ia_archiver
- Bing:bingbot
- 有道:YodaoBot、OutfoxBot
- 搜狗:sogou spider
- SOSO:sosospider
- 360:360spider
來源:西部數碼