Skip to content

Commit

Permalink
add marking bot sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal committed Jun 8, 2024
1 parent 9479310 commit 24df06d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/nginx/bitrix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -115,4 +114,5 @@ location ~ \.php$ {

fastcgi_pass php-upstream;
include fastcgi.conf;
include bots.conf;
}
7 changes: 2 additions & 5 deletions config/nginx/bots.conf
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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

12 changes: 12 additions & 0 deletions config/nginx/conf.d/bots_substutute.conf
Original file line number Diff line number Diff line change
@@ -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';
}

0 comments on commit 24df06d

Please sign in to comment.