Welcome! Log In Create A New Profile

Advanced

Re: using $upstream* variables inside map directive

Ruslan Ermilov
May 07, 2014 08:46AM
On Wed, May 07, 2014 at 01:38:04AM -0400, Kirill K. wrote:
> Hello,
> I'm trying to avoid caching of small responses from upstreams using map:
> map $upstream_http_content_length $dontcache {
> default 0;
> ~^\d\d$ 1;
> ~^\d$ 1;
> }
>
> Unfortunatelly, nginx seems to ignore $upstream* variables at the map
> processing stage, hence variables like $upstream_http_content_length or
> $upstream_response_length stay empty when map directive is processed (this
> can be observed in debug log as "http map started" message). In case I use
> non-upstream related variables, a map works as expected.
>
> Question: is there any way to use $upstream* vars inside the map directive,
> or maybe someone can offer alternative way to detect small upstream response
> in order to bypass cache?

If you use $dontcache with proxy_cache_bypass, then it's expected
behavior. At the time proxy_cache_bypass is evaluated, there's no
response yet, so the $upstream_http_* do not exist.

If you try to use $dontcache with proxy_no_cache ONLY, it'll work,
because the latter is evaluated _after_ obtaining a response.

If you use it both with proxy_cache_bypass and proxy_no_cache,
please realize that using it with proxy_cache_bypass makes no
sense, and then the fact that "map" creates the so-called
cacheable variables plays its role.

I have a patch for "map" that makes map variables "volatile".
If you absolutely need such a "map" behavior, I can send it
to you for testing, but better limit the use of $upstream_http_*
to only proxy_no_cache.

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

using $upstream* variables inside map directive

Kirill K. May 07, 2014 01:38AM

Re: using $upstream* variables inside map directive

Jonathan Matthews May 07, 2014 06:32AM

Re: using $upstream* variables inside map directive

Kirill K. May 07, 2014 07:44AM

Re: using $upstream* variables inside map directive

Ruslan Ermilov May 07, 2014 08:46AM

Re: using $upstream* variables inside map directive

Kirill K. May 07, 2014 08:53AM

Re: using $upstream* variables inside map directive

Ruslan Ermilov May 07, 2014 10:40AM

Re: using $upstream* variables inside map directive

Kirill K. May 07, 2014 03:44PM

Re: using $upstream* variables inside map directive

unoobee November 11, 2020 12:55PM

Re: using $upstream* variables inside map directive

ru@nginx.com November 11, 2020 02:14PM

Re: using $upstream* variables inside map directive

unoobee November 12, 2020 02:33AM

Re: using $upstream* variables inside map directive

Francis Daly November 12, 2020 03:36AM

Re: using $upstream* variables inside map directive

unoobee November 12, 2020 04:58AM

Re: using $upstream* variables inside map directive

Francis Daly November 12, 2020 09:36AM

Re: using $upstream* variables inside map directive

unoobee November 12, 2020 11:00AM

Re: using $upstream* variables inside map directive

Francis Daly November 12, 2020 11:50AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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