I'm actually a little surprised that I couldn't find anything after a couple hours of googling, but the problem is as follows:
I want nginx to serve as my throttle for my API.
My config file contains a well-cited example of limit_req_zone
:
limit_req_zone $binary_remote_addr zone=limit:2m rate=10r/m;
along with my location
directive containing the expected limit_req zone=limit nodelay;
I would love to have nginx attach headers to the response message for both the X-RateLimit-Remaining
and X-RateLimit-Reset
attributes. Basically have nginx use the active count of the rate=10r/m
to populate X-RateLimit-Remaining
and timeframe of the same rate=10r/m
value to populate X-RateLimit-Reset
with how many seconds are left before a refresh.
http {
limit_req_zone $binary_remote_addr zone=login:10m rate=2r/s;
limit_req_status 429;
limit_conn_status 429;
server {
listen 80;
server_name [removed];
location / {
limit_req zone=limit nodelay;
proxy_pass http://reverse-proxy-example;
add_header X-RateLimit-Remaining [nginx variable?];
add_header X-RateLimit-Reset [nginx variable?]
}
}
Thoughts? Possible? Would love to avoid hitting the application to get these numbers.