How do you do rate limiting and abuse protection in nginx?
IntermediateProductionLoad Balancing, Proxies & nginx in Production
Answer
limit_req_zone $binary_remote_addr zone=perip:10m rate=10r/s;
limit_conn_zone $binary_remote_addr zone=connperip:10m;
server {
limit_req zone=perip burst=20 nodelay;
limit_conn connperip 20;
limit_req_status 429;
}
Behind a CDN, key on the real client IP (set_real_ip_from plus real_ip_header) or you will rate limit the CDN itself.
More on Load Balancing, Proxies & nginx in Production
How do you choose between ALB, NLB and an nginx or Envoy fleet?IntermediateHow do you tune ALB idle timeout and backend keep-alive to avoid 502s?IntermediateWhich nginx directives matter most for a production reverse proxy?IntermediateHow do you achieve zero-downtime configuration reloads in nginx and HAProxy?IntermediateHow would you design a highly available load-balancing tier on-prem or in a colo?AdvancedHow do you perform a blue/green deployment at the load balancer level?Intermediate