Skip to content

Set stricter rate limits for web requests #10594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docker/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ http {
1 $binary_remote_addr;
}

limit_req_zone $rate_limit_key zone=web_limit:10m rate=200r/m;
# Matches other sites
limit_req_zone $rate_limit_key zone=web_limit:10m rate=1r/s;
# Higher rate for APIs since they are cheaper and we often hit them
# multiple times per page load.
limit_req_zone $rate_limit_key zone=api_limit:10m rate=200r/m;
# 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;

Expand Down
19 changes: 16 additions & 3 deletions docker/web_nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ server {
}

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

if ($http_user_agent ~ (Bytespider) ) {
Expand All @@ -102,10 +101,24 @@ server {

}

location ~ ^(/api/.*|.*\.json)$ {
limit_req zone=api_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;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Scheme $scheme;
}

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

# randomly sorting will be removed. For now just return 200
Expand Down
Loading