Welcome! Log In Create A New Profile

Advanced

Re: using $upstream* variables inside map directive

Jonathan Matthews
May 07, 2014 06:32AM
On 7 May 2014 06:38, Kirill K. <nginx-forum@nginx.us> 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?

I don't explicitly know how to achieve what you're trying to, but I
seem to recall mention on this list that a map's value gets stuck
(per-request) the first time it's evaluated. I might be
misremembering, but this does ring a bell.

So - is your map somehow being evaluated /before/ the upstream vars
are available? Does your config perhaps cause it to be evaluated when
the initial request arrives, to see if the response should be served
from cache; then the request is proxy_pass'd, then after receiving a
response the caching bypass config is examined but to no avail as the
map has "stuck" with the initially set value?

Sorry I can't be more specific - I'm sure others can help more definitively!

J

_______________________________________________
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: 117
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready