Skip to content

Instantly share code, notes, and snippets.

Created September 24, 2013 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/bf347d5302b3463f970b to your computer and use it in GitHub Desktop.
Save anonymous/bf347d5302b3463f970b to your computer and use it in GitHub Desktop.
http {
limit_req_zone $binary_remote_addr zone=STATIC_LIMIT_REQ:1m rate=50r/s;
limit_req_zone $binary_remote_addr zone=DYNAMIC_LIMIT_REQ:1m rate=5r/s;
# set up "global" limit_req for all requests, including static files:
limit_req zone=STATIC_LIMIT_REQ burst=100 nodelay;
server {
server_name mydomain.com;
location /admin {
# This works fine!
limit_req zone=DYNAMIC_LIMIT_REQ burst=5 nodelay;
# ...
proxy_pass http://admin;
}
location / {
# try for page-cached files, so don't want to rate limit here:
try_files /maintenance.html $cache_path @dynamic;
}
location @dynamic {
# Here all requests will be passed to our backend servers, so we want to limit but...
# This limit_req is ignored!
limit_req zone=DYNAMIC_LIMIT_REQ burst=5 nodelay;
# ...
proxy_pass http://backend;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment