Данная статья предлагает подробное руководство по использованию Cloudflare для эффективного сокращения присутствия на вашем веб-ресурсе от 70% до 99% нежелательных ботов, обходя дорогостоящие услуги агентств. Это становится особенно актуальным, когда ваш сайт поднимается в поисковых результатах, привлекая внимание ботов, имитирующих действия пользователей для искажения статистики.
Для начала вам просто понадобится бесплатный аккаунт на Cloudflare. Процесс регистрации и подключения к вашему сайту прост и широко известен, поэтому мы опустим подробности.
Ключевым этапом является настройка правил фильтрации. В бесплатной версии Cloudflare доступно до пяти таких правил, что обычно достаточно для наших целей.
Пример добавления правил в WAF
Вам потребуется:
Пример заполненных команд для сайта
Эти меры помогут существенно снизить количество нежелательных ботов на вашем сайте, защищая его от искажения аналитических данных и потенциальных атак.
Пример команды разрешения доступа к сайту ботов Google и Яндекса
Кликаем на » Edit Expression «, вводим следующую команду:
(http.user_agent contains "Google") or (http.user_agent contains "Yandex")
Затем выбираем » Use expression builder», устанавливаем действие на » SKIP», отмечаем все необходимые флажки и нажимаем на » Deploy».
Правило доступа полезных ботов на сайт
Вам нужно будет определить IP-адрес или его ASNUM. Если вы не знаете, как это сделать, обратитесь за помощью в службу поддержки вашего хостинга. Также не забудьте разрешить все запросы к wp-cron.php, если ваш сайт работает на WordPress. Для этого используйте конструктор выражений, чтобы ввести соответствующую команду.
Пример команды:
(ip.geoip.asnum eq 22612) or (ip.geoip.asnum eq 62371) or (ip.geoip.asnum eq 47583) or (http.request.uri contains "/wp-cron.php")
Затем, используйте конструктор выражений, установите действие на «Пропустить», пометьте все необходимые флажки и внесите изменения, нажав «Развернуть».
Из-за ограничения в пять правил и большого количества ботов мы разделили фильтры на две части, чтобы вместить все необходимые условия. Важно адаптировать список запрещенных стран под ваш сайт, например, в примере мы блокируем Болгарию, но это может быть неактуально для вас.
Первая часть обработки включает блокировку посетителей из определенных стран и ботов по их идентификаторам в User Agent. Пример для вставки:
(ip.geoip.country eq "CN") or (ip.geoip.country eq "UA") or (ip.geoip.country eq "IR") or (ip.geoip.country eq "IN") or (ip.geoip.continent eq "AF") or (ip.geoip.country eq "SG") or (ip.geoip.country eq "GB") or (ip.geoip.country eq "PL") or (ip.geoip.country eq "ID") or (ip.geoip.country eq "TH") or (ip.geoip.country eq "HK") or (ip.geoip.country eq "CH") or (ip.geoip.country eq "BG") or (ip.geoip.country eq "CZ") or (ip.geoip.country eq "SC") or (ip.geoip.country eq "CA") or (http.user_agent contains "ahrefs.com") or (http.user_agent contains "Abonti") or (http.user_agent contains "AspiegelBot") or (http.user_agent contains "aggregator") or (http.user_agent contains "AhrefsBot") or (http.user_agent contains "Aport") or (http.user_agent contains "asterias") or (http.user_agent contains "Baiduspider") or (http.user_agent contains "BDCbot") or (http.user_agent contains "bidswitchbot") or (http.user_agent contains "Birubot") or (http.user_agent contains "BLEXBot") or (http.user_agent contains "BUbiNG") or (http.user_agent contains "BuiltBotTough") or (http.user_agent contains "Bullseye") or (http.user_agent contains "BunnySlippers") or (http.user_agent contains "Butterfly") or (http.user_agent contains "ca-crawler") or (http.user_agent contains "CamontSpider") or (http.user_agent contains "CCBot") or (http.user_agent contains "Cegbfeieh") or (http.user_agent contains "CheeseBot") or (http.user_agent contains "CherryPicker") or (http.user_agent contains "coccoc") or (http.user_agent contains "CopyRightCheck") or (http.user_agent contains "cosmos") or (http.user_agent contains "crawler")
После настройки выражения переходим к использованию конструктора выражений, устанавливаем действие как «BLOCK», затем активируем это правило, нажимая на «Развернуть».
Для второй части ваших настроек:
(http.user_agent contains "Crescent") or (http.user_agent contains "CyotekWebCopy/1.7") or (http.user_agent contains "CyotekHTTP/2.0") or (http.user_agent contains "DataForSeoBot") or (http.user_agent contains "DeuSu") or (http.user_agent contains "discobot") or (http.user_agent contains "DittoSpyder") or (http.user_agent contains "DnyzBot") or (http.user_agent contains "DomainCrawler") or (http.user_agent contains "DotBot") or (http.user_agent contains "Download Ninja") or (http.user_agent contains "EasouSpider") or (http.user_agent contains "EmailCollector") or (http.user_agent contains "EmailSiphon") or (http.user_agent contains "EmailWolf") or (http.user_agent contains "EroCrawler") or (http.user_agent contains "Exabot") or (http.user_agent contains "ExtractorPro") or (http.user_agent contains "Ezooms") or (http.user_agent contains "FairShare") or (http.user_agent contains "Fasterfox") or (http.user_agent contains "FeedBooster") or (http.user_agent contains "Foobot") or (http.user_agent contains "Genieo") or (http.user_agent contains "GetIntent Crawler") or (http.user_agent contains "Gigabot") or (http.user_agent contains "gold crawler") or (http.user_agent contains "GrapeshotCrawler") or (http.user_agent contains "grub-client") or (http.user_agent contains "Harvest") or (http.user_agent contains "hloader") or (http.user_agent contains "httplib") or (http.user_agent contains "HTTrack") or (http.user_agent contains "humanlinks") or (http.user_agent contains "HybridBot") or (http.user_agent contains "ia_archiver") or (http.user_agent contains "ieautodiscovery") or (http.user_agent contains "Incutio") or (http.user_agent contains "InfoNaviRobot") or (http.user_agent contains "InternetSeer") or (http.user_agent contains "IstellaBot") or (http.user_agent contains "Java") or (http.user_agent contains "Java/1.") or (http.user_agent contains "JamesBOT") or (http.user_agent contains "JennyBot") or (http.user_agent contains "JS-Kit") or (http.user_agent contains "k2spider") or (http.user_agent contains "Kenjin Spider") or (http.user_agent contains "Keyword Density/0.9") or (http.user_agent contains "kmSearchBot") or (http.user_agent contains "larbin") or (http.user_agent contains "LexiBot") or (http.user_agent contains "libWeb") or (http.user_agent contains "libwww") or (http.user_agent contains "Linguee") or (http.user_agent contains "LinkExchanger") or (http.user_agent contains "LinkextractorPro") or (http.user_agent contains "linko") or (http.user_agent contains "LinkScan/8.1a Unix") or (http.user_agent contains "LinkWalker") or (http.user_agent contains "LinkpadBot") or (http.user_agent contains "lmspider") or (http.user_agent contains "LNSpiderguy") or (http.user_agent contains "ltx71") or (http.user_agent contains "lwp-trivial") or (http.user_agent contains "lwp-trivial") or (http.user_agent contains "magpie") or (http.user_agent contains "Mata Hari") or (http.user_agent contains "MaxPointCrawler") or (http.user_agent contains "MegaIndex")
Аналогично, через конструктор выражений устанавливаем действие на «BLOCK» и применяем изменения, выбрав «Развернуть».
Большая часть ботов не использует шифрование SSL и посещает сайт с необычных IP-адресов. Данная информация взята с partnerkin.com и немного адаптирована. Вот соответствующее правило:
(ip.src in {::/0}) or (not ssl) or (not http.request.version in {"HTTP/2" "HTTP/3" "SPDY/3.1"})
Если вы наблюдаете множество ботов, приходящих напрямую без реферера, то необходимо использовать такое условие:
or (http.referer eq "")
Это правило принудит посетителей, пришедших напрямую на сайт без реферера, проходить проверку капчей. Обдумайте, подходит ли такой подход в вашем случае.
Далее, выберите опцию «Управляемый вызов» в действиях и примените настройку, кликнув «Развернуть».
Теперь ваш сайт стал более защищенным! Благодаря этим настройкам, удаётся отфильтровывать до 99% ботов, но, к сожалению, некоторые могут всё равно просочиться.