Welcome! Log In Create A New Profile

Advanced

Map directive key too long for rate limiting

Posted by blee 
Map directive key too long for rate limiting
January 01, 2021 01:17AM
My end goal is to implement a rate limit based on the authorization header value and, as a fallback, the client IP.

Here is the map directive, which is working fine.

```
map $http_authorization $rate_limit {
default $binary_remote_addr;
'~*.*' $http_authorization;
}
```

However, it seems that the authorization header value is too lengthy, and is greater than 255 bytes.

```
2021/01/01 05:51:18 [error] 28#28: *287 the value of the "$rate_limit" key is more than 255 bytes: "Bearer XXX...XXX", client: 0.0.0.0, server: _, request: "GET / HTTP/1.1", host: "host.com"
```

How would you go about properly shortening `$rate_limit`? Any suggestions? Is there any way to increase this 255 byte limit within the nginx.conf file?

I attempted to truncate the token value with something like `"~^(.{25})" $http_authorization;`, but that didn't seem to work either because I am seeing the same error.

Thank you!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 74
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready