Skip to content

Commit

Permalink
Merge pull request #10023 from scottbarnes/help-manage-bots-hitting-a…
Browse files Browse the repository at this point in the history
…uthors

Help slow down bots hitting /authors
  • Loading branch information
cdrini authored Nov 12, 2024
2 parents 23045ac + 7cdf833 commit 4a82cf5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docker/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ http {
# Set a more permissive limit for covers because some pages might load 20+ covers.
limit_req_zone $rate_limit_key zone=cover_limit:10m rate=400r/m;

# For returning 200 when someone tries to randomly sort author results.
map $arg_sort $is_random_sort {
default 0;
~^random_.* 1;
}

# Things are mounted into here by the docker compose file
include /etc/nginx/sites-enabled/*;
}
29 changes: 25 additions & 4 deletions docker/web_nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ server {
}

location / {
# Web rate limit.
limit_req zone=web_limit burst=200 nodelay;
limit_req_status 429;

if ($http_user_agent ~ (Bytespider) ) {
return 444;
}

proxy_pass http://webnodes;
proxy_set_header Host $http_host;

Expand All @@ -83,14 +91,27 @@ server {
# app server is http only.
proxy_set_header X-Scheme $scheme;

if ($http_user_agent ~ (Bytespider) ) {
return 444;
}

}

# Log likely bots caught in /authors random loop.
location ~* ^/authors/.* {
# Web rate limit.
limit_req zone=web_limit burst=200 nodelay;
limit_req_status 429;

# randomly sorting will be removed. For now just return 200
if ($is_random_sort = 1) {
return 200 "";
}

if ($http_user_agent ~ (Bytespider) ) {
return 444;
}

proxy_pass http://webnodes;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Scheme $scheme;
}

location ^~ /.well-known/acme-challenge/ {
Expand Down

0 comments on commit 4a82cf5

Please sign in to comment.