Welcome! Log In Create A New Profile

Advanced

Rate Limit not applied when mapping $upstream_http_ headers

Markus Grobelin
October 01, 2021 04:52AM
Hy everybody,

I have a reverse-proxy setup with an upstream application that sets a header (x_tenant_id).

Based on that headers value, I want to apply a rate limit to clients.

I verified the rate limit applies* properly, when a usual request header (e.g. $http_x_tenant_id) is mapped. However the config below does not map $upstream_http_x_tenant_id** at all.

Any advice how to achieve rate limiting using such $upstream_http_ headers?

Thanks in advance,
Markus

* siege -c 10 -t5S -H 'x-tenant-id: 503' <someurl>

**
upstream myupstream {
server 10.10.100.0:8000;
}

# does not work
map $upstream_http_x_tenant_id $limit_key {
123 $binary_remote_addr;
503 $binary_remote_addr;
default "";
}

server {
[...]
location / {
# Rate limiting for some tenants
limit_req zone=limit_key;
limit_req_status 444;
uwsgi_read_timeout 300s;
uwsgi_send_timeout 300s;
uwsgi_pass myupstream;
include /etc/nginx/uwsgi_params;
}
[...]
}

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Rate Limit not applied when mapping $upstream_http_ headers

Markus Grobelin October 01, 2021 04:52AM

Re: Rate Limit not applied when mapping $upstream_http_ headers

Maxim Dounin October 01, 2021 01:34PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 272
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready