Maxim Dounin
October 01, 2021 01:34PM
Hello!

On Fri, Oct 01, 2021 at 10:47:01AM +0200, Markus Grobelin wrote:

> 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?

Request rate limiting, as configured with the limit_req rate
directive (not to be confused with response transmission rate
limiting, limit_rate), happens before processing a request, that
is, before the request is sent to the upstream server and a
response is received. As such, you cannot rely on variables only
available when a response is received from the upstream server,
such as $upstream_http_* variables.

If you want to reject requests based on the information only
available on the upstream server, the best solution might be to
actually reject requests on the upstream server. If you have to
do it on nginx for some reason, it should be possible to configure
things using X-Accel-Redirect redirections, though this going to
be a complex configuration, and it will do two upstream request
instead of just one. A better approach might be to re-think your
limiting configuration to use something directly available from
the request.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
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: 238
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