Skip to content

Commit

Permalink
move bots detection to separate nginx config file
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal committed Jun 8, 2024
1 parent 971421c commit 9479310
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
22 changes: 1 addition & 21 deletions config/nginx/bitrix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,8 @@ ssl_certificate /etc/nginx/letsencrypt/live/favor-group.ru/fullchain.pem;
ssl_certificate_key /etc/nginx/letsencrypt/live/favor-group.ru/privkey.pem;
ssl_trusted_certificate /etc/nginx/letsencrypt/live/favor-group.ru/chain.pem;

## block the bad actors
set $block 0;

if ($bad_agent) {
set $block 1;
}

if ($bad_ip) {
set $block 1;
}

# don't block bots users from using sitemap
if ($request_uri ~ ^/sitemap/$) {
set $block 0;
}

#if ($block) {
# return 302 https://$host/sitemap/;
#}
## end of block

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
18 changes: 18 additions & 0 deletions config/nginx/bots.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## 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) {
set $block 1;
}

if ($bad_ip) {
set $block 1;
}

if ($block) {
# return 302 https://$host/sitemap/;
}
## end of block

1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ services:
- ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./config/nginx/bitrix.conf:/etc/nginx/bitrix.conf:ro
- ./config/nginx/fastcgi.conf:/etc/nginx/fastcgi.conf:ro
- ./config/nginx/bots.conf:/etc/nginx/bots.conf:ro
- ./config/nginx/security_headers.conf:/etc/nginx/security_headers.conf:ro
- ./config/nginx/static-cdn.conf:/etc/nginx/static-cdn.conf:ro
- ./config/nginx/conf.d:/etc/nginx/conf.d:ro
Expand Down

0 comments on commit 9479310

Please sign in to comment.