From 24df06d4d797f70ac713138d5b7128df343c2470 Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Sat, 8 Jun 2024 22:33:11 +0000 Subject: [PATCH] add marking bot sessions --- config/nginx/bitrix.conf | 2 +- config/nginx/bots.conf | 7 ++----- config/nginx/conf.d/bots_substutute.conf | 12 ++++++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 config/nginx/conf.d/bots_substutute.conf diff --git a/config/nginx/bitrix.conf b/config/nginx/bitrix.conf index 2b741a4..bddcdf6 100644 --- a/config/nginx/bitrix.conf +++ b/config/nginx/bitrix.conf @@ -3,7 +3,6 @@ ssl_certificate_key /etc/nginx/letsencrypt/live/favor-group.ru/privkey.pem; ssl_trusted_certificate /etc/nginx/letsencrypt/live/favor-group.ru/chain.pem; include security_headers.conf; -include bots.conf; # CSP headers, too dangerous to include to the code someone will copy and run include /etc/nginx/private.conf.d/bitrix_csp_headers.conf; @@ -115,4 +114,5 @@ location ~ \.php$ { fastcgi_pass php-upstream; include fastcgi.conf; + include bots.conf; } diff --git a/config/nginx/bots.conf b/config/nginx/bots.conf index 36137fe..11a1a8d 100644 --- a/config/nginx/bots.conf +++ b/config/nginx/bots.conf @@ -1,6 +1,4 @@ ## mark the bad actors -# do not include this file for static resources as it prevents caching -# https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_cache_valid set $block 0; if ($bad_agent) { @@ -11,8 +9,7 @@ if ($bad_ip) { set $block 1; } -if ($block) { -# return 302 https://$host/sitemap/; -} +sub_filter '// mark bots using nginx rewrite' $conditional_filter; +sub_filter_once on; ## end of block diff --git a/config/nginx/conf.d/bots_substutute.conf b/config/nginx/conf.d/bots_substutute.conf new file mode 100644 index 0000000..d7fd986 --- /dev/null +++ b/config/nginx/conf.d/bots_substutute.conf @@ -0,0 +1,12 @@ +map $block $conditional_filter { + 1 '// mark bots using nginx rewrite + ym(favorGroupConfig.yandexMetricsIDGlobal, "userParams", { "bot": true }); + ym(favorGroupConfig.yandexMetricsIDRegional, "userParams", { "bot": true }); + gtag({ + "event": "bot_session", + "event_category": "Bot", + "event_label": "Bot Detected" + });'; + default '// mark bots using nginx rewrite'; +} +