Skip to content

Instantly share code, notes, and snippets.

@sempr
Last active January 11, 2024 06:48
Show Gist options
  • Save sempr/8cde553d1f8228b8e8364487e5871b21 to your computer and use it in GitHub Desktop.
Save sempr/8cde553d1f8228b8e8364487e5871b21 to your computer and use it in GitHub Desktop.
nginx rate limit config sample
# https://zhaox.github.io/nginx/2019/09/05/explain-nginx-rate-limit
# 20 per second, 50ms each
limit_req_zone $remote_user zone=user_limit:10m rate=10r/s;
limit_req_zone $my_id zone=one:10m rate=20r/m;
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
proxy_pass https://httpbin.org;
}
location ~ ^/links/(?<my_id>\d+)/\d+ {
limit_req zone=one;
limit_req_status 429;
proxy_pass https://httpbin.org;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment