Skip to content

Instantly share code, notes, and snippets.

View lcrilly's full-sized avatar

Liam Crilly lcrilly

View GitHub Profile
@lcrilly
lcrilly / sinbin.conf
Created May 17, 2024 17:01
Implementing a sin bin with NGINX Plus
limit_req_zone $remote_addr zone=per_ip:1M rate=5r/s sync; # Cluster-aware rate limiting
limit_req_status 429;
keyval_zone zone=sinbin:1M timeout=60 sync;
keyval $remote_addr $sinbin_rate zone=sinbin;
# Frontend
#
server {
listen 80;
@lcrilly
lcrilly / README.md
Created February 20, 2026 09:36
Request quotas for NGINX

NGINX configuration to implement finite request quotas

This configuration implements finite request quotas. Without changes, each client IP address is limted to 10 requests per minute.

With each response, a header RateLimit is returned that indicates the remaining quota for that client. The format of this header follows the draft RFC for this field. https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit-headers/

NGINX JavaScript (njs) is used to manage the quota counter and perform the quota reset.