How to create an NGinx rate-limiting zone based on integer?

by Mikhail T.   Last Updated November 14, 2017 18:00 PM

We need to rate-limit by value of a cookie, that's always an integer (well below 65000). Though transmitted in decimal form and thus, possibly, taking as much as 5 bytes, the value can be stored in two bytes (uint16_t).

Currently, we are using

limit_req_zone $cookie_FOO zone=foo_ratelimit:1m rate=37r/s;

which, I suspect, stores the entire length of the decimal representation of the value. Can I use something like int($cookie_FOO) as the key instead -- to force it down to uint32_t or uint16_t, the way NGinx manual recommends using $binary_remote_addr over $remote_addr?

Related Questions

Rate limit misconfigured bots

Updated May 15, 2015 22:00 PM

Nginx throttle download speed based on filesize

Updated March 23, 2017 10:00 AM

NGINX not evaluating variables?

Updated April 24, 2017 10:00 AM