允许搜索引擎蜘蛛访问,识别蜘蛛的正确姿势

网站在使用CDN后,由于防火墙默认规则,可能会出现搜索引擎蜘蛛无法正常访问网站,从而造成网站无法收录或收录量下降情况。我的blog前段时间在使用cloudflare cdn(以下简称CF)后,就出现百度蜘蛛无法正常访问的情况,本文将以CF举例,告诉大家如果设置防火墙规则,允许蜘蛛访问。

一、如何正确识别搜索引擎蜘蛛

识别搜索引擎蜘蛛基本上有二种方法。

1、通过蜘蛛ip识别,将蜘蛛ip加入防火墙白名单。这是一种可行的方法,网络上也有很多类似的教程,但是搜索引擎新增或删除ip不能第一时间知道,维护一份ip列表真的很辛苦。

2、使用User-Agent识别搜索引擎蜘蛛,这是我推荐的方法。各搜索引擎在其官方网站均公布了自己的UA信息。

例如:
  • 百度:https://ziyuan.baidu.com/college/articleinfo?id=1002
  • 谷歌:https://developers.google.com/search/docs/crawling-indexing/overview-google-crawlers
  • 必应:https://www.bing.com/webmasters/help/which-crawlers-does-bing-use-8c184ec0
              https://blogs.bing.com/webmaster/april-2022/Announcing-user-agent-change-for-Bing-crawler-bingbot
  • 搜狗:http://help.sogou.com/guide.html#3
  • 360搜索:http://www.so.com/help/help_3_2.html
  • 腾讯soso:http://help.soso.com/webspider.htm
                      http://help.soso.com/soso-image-spider.htm
                      http://help.soso.com/webspider.shtml

二、设置防火墙规则,允许蜘蛛访问

CDN服务提供商已经考虑到了这个问题,例如CF在防火墙规则里包含有合法机器人爬虫(Known Bots)字段,维护了一份搜索引擎蜘蛛列表,用户可以针对合法机器人爬虫选择允许通过或进行阻止。但是CF是一家海外公司,百度或搜狗这些国内用户经常使用的搜索引擎,对于CF来说,权重并不高。会出现百度的某些蜘蛛并没有在CF的合法机器人爬虫列表里,因此需要我们自己根据常用搜索引擎提供的UA信息,创建防火墙规则。

1、创建防火墙规则,允许合法机器人爬虫通过,这条规则创建后,大多数搜索引擎蜘蛛都可以正常访问。

01.webp2、根据百度提供的UA信息,针对百度蜘蛛创建防火墙规则。

02.webp以下为针对百度蜘蛛创建的表达式,大家可以直接使用:

(http.user_agent eq "Mozilla/5.0 (Linux;u;Android 4.2.2;zh-cn;) AppleWebKit/534.46 (KHTML,like Gecko)Version/5.1 Mobile Safari/10600.6.3 (compatible; Baiduspider/2.0;+http://www.baidu.com/search/spider.html)") or (http.user_agent eq "Mozilla/5.0 (iPhone;CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko)Version/9.0 Mobile/13B143 Safari/601.1 (compatible; Baiduspider-render/2.0;+http://www.baidu.com/search/spider.html) ") or (http.user_agent eq "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)") or (http.user_agent eq "Mozilla/5.0 (compatible; Baiduspider-render/2.0; +http://www.baidu.com/search/spider.html)") or (http.user_agent eq "Mozilla/5.0 (iPhone;CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko)Version/9.0 Mobile/13B143 Safari/601.1 (compatible; Baiduspider-render/2.0;Smartapp; +http://www.baidu.com/search/spider.html)")

3、根据谷歌提供的UA信息,针对谷歌蜘蛛创建防火墙规则。

03.webp以下为针对谷歌蜘蛛创建的表达式,大家可以直接使用:

(http.user_agent contains "APIs-Google") or (http.user_agent contains "AdsBot-Google") or (http.user_agent contains "Mediapartners-Google") or (http.user_agent contains "Googlebot") or (http.user_agent contains "Mediapartners-Google") or (http.user_agent contains "FeedFetcher-Google") or (http.user_agent contains "Google-Read-Aloud") or (http.user_agent contains "DuplexWeb-Google") or (http.user_agent contains "googleweblight") or (http.user_agent contains "Storebot-Google") or (http.user_agent contains "Google-Site-Verification")

4、根据其他搜索引擎提供的UA信息,针对必应蜘蛛、360搜索引擎蜘蛛、腾讯soso蜘蛛、搜狗搜索引擎蜘蛛、雅虎搜索引擎蜘蛛创建防火墙规则。

04.webp以下为针对必应蜘蛛、360搜索引擎蜘蛛、腾讯soso蜘蛛、搜狗搜索引擎蜘蛛、雅虎搜索引擎蜘蛛创建的表达式,大家可以直接使用:

(http.user_agent eq "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)") or (http.user_agent contains "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)") or (http.user_agent contains "(compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)") or (http.user_agent eq "Mozilla/5.0 (compatible; adidxbot/2.0; +http://www.bing.com/bingbot.htm)") or (http.user_agent eq "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 (compatible; adidxbot/2.0; +http://www.bing.com/bingbot.htm)") or (http.user_agent eq "Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 530) like Gecko (compatible; adidxbot/2.0; +http://www.bing.com/bingbot.htm)") or (http.user_agent contains "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; MicrosoftPreview/2.0; +https://aka.ms/MicrosoftPreview)") or (http.user_agent contains "360Spider") or (http.user_agent eq "Sosospider+(+http://help.soso.com/webspider.htm)") or (http.user_agent eq "Sosoimagespider+(+http://help.soso.com/soso-image-spider.htm)") or (http.user_agent contains "Sogou web spider") or (http.user_agent contains "Sogou inst spider") or (http.user_agent eq "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)")

5、当某个蜘蛛访问时,首先判断这个蜘蛛是否为合法机器人爬虫(Known Bots),如果是,直接放行。如果否,进入第二条防火墙规则进行判断。如下图所示,百度搜索引擎的某些蜘蛛访问时,并没有包含在合法机器人爬虫(Known Bots)列表,进入baiduSpider规则判断后,进行放行。

05.webp


本文出处:HiFeng'Blog
本文链接:
https://hicairo.com/post/36.html
版权声明:本博客所有文章除特别声明外,均采用CC BY-NC-SA许可协议。转载请注明出处!