Welcome! Log In Create A New Profile

Advanced

Nginx $upstream_cache_status not available when used in rate limiting

Linna.Ding
July 18, 2016 03:28PM
Hi,

I use Nginx as reverse proxy, and I would like to rate limit the requests
to origin server, but only limit the requests with cache status EXPIRED. I
just tested with a map "cache_key", and the rate limiting doesn't work, the
$cache_key was logged as empty string. But changing $upstream_cache_status
to non-upstream variables like $remote_addr and adding an IP match value
will make the rate limiting work. The zone I defined like so:
limit_req_zone $cache_key zone=cache_host:1m rate=1r/m;
map $upstream_cache_status $cache_key {
EXPIRED $host;
default "";
}
I enabled cache setting in nginx.conf, and one of my server chunk uses the
rate limit zone like below:
limit_req zone=cache_host busrt=1;

Is this because $upstream_cache_status value is set after the request is
sent to origin server and got the response, while $cache_key is used in
rate limit zone which checked before the request was sent to origin server? If
so, is there a recommended way to implement rate limiting only for requests
with specific cache status?

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

Nginx $upstream_cache_status not available when used in rate limiting

Linna.Ding July 18, 2016 03:28PM

Re: Nginx $upstream_cache_status not available when used in rate limiting

linnading July 20, 2016 02:03PM

Re: Nginx $upstream_cache_status not available when used in rate limiting

Francis Daly July 20, 2016 02:18PM

Re: Nginx $upstream_cache_status not available when used in rate limiting

linnading July 20, 2016 02:52PM

Re: Nginx $upstream_cache_status not available when used in rate limiting

Francis Daly July 20, 2016 05:30PM

Re: Nginx $upstream_cache_status not available when used in rate limiting

Valentin V. Bartenev July 20, 2016 05:56PM

Re: Nginx $upstream_cache_status not available when used in rate limiting

linnading July 21, 2016 10:51AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 304
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