Last active
January 31, 2023 20:03
-
-
Save xxiz/15dce0a76d23141c356715f15d209748 to your computer and use it in GitHub Desktop.
rate limiting a specific location via nginx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http { | |
limit_req_zone $binary_remote_addr zone=limit_req_zone_1:10m rate=10r/s; | |
server { | |
listen 80; | |
server_name example.com; | |
location /index/ { | |
limit_req zone=limit_req_zone_1 burst=10; | |
auth_basic "Restricted Access"; | |
auth_basic_user_file /path/to/htpasswd; | |
proxy_next_upstream error timeout http_500 http_502 http_503 http_504; | |
proxy_connect_timeout 10s; | |
proxy_read_timeout 10s; | |
proxy_pass http://upstream_server; | |
} | |
error_page 401 = @error401; | |
location @error401 { | |
limit_req_status 429; | |
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s; // modify 's' with 24h for 24h timeout | |
return 429; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment