Skip to content

Instantly share code, notes, and snippets.

@muresan
Created February 21, 2019 01:18
Show Gist options
  • Select an option

  • Save muresan/382c3ecc68125133dc7450c0c8a310c6 to your computer and use it in GitHub Desktop.

Select an option

Save muresan/382c3ecc68125133dc7450c0c8a310c6 to your computer and use it in GitHub Desktop.
# limit the number of connections to 1 per second and allow to burst to 10
limit_req_zone $http_x_forwarded_for zone=application:10m rate=1r/s; # For Load Balanced environments
#limit_req_zone $remote_addr zone=application:10m rate=1r/s; # For Single Instance environments
limit_req zone=application burst=10 nodelay;
limit_req_status 429;
limit_conn_status 429;
# pass real IP from client to NGINX
real_ip_header X-Forwarded-For;
set_real_ip_from 0.0.0.0/0;
server {
# set error page for HTTP code 429
error_page 429 @ratelimit;
location @ratelimit {
return 429 'Connection Limit Exceeded\n';
}
}
Copy link

ghost commented Feb 4, 2024

you should consider adding a "resolver" param in the http block in case you want to use secure dns resolver with unbound.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment