Nginx multiple upstream map conditions

c0nw0nk nginx-forum at forum.nginx.org
Thu Sep 1 01:17:32 UTC 2016


c0nw0nk Wrote:
-------------------------------------------------------
> Francis Daly Wrote:
> -------------------------------------------------------
> > On Wed, Aug 31, 2016 at 01:30:30PM -0400, c0nw0nk wrote:
> > 
> > Hi there,
> > 
> > > Thanks works a treat is it possible or allowed to do the
> following
> > in a
> > > nginx upstream map ? and if so how i can't figure it out.
> > 
> > I think it is logically impossible.
> > 
> > > I cache with the following key.
> > > fastcgi_cache_key
> > > "$session_id_value$scheme$host$request_uri$request_method";
> > 
> > fastcgi_cache_key is the thing that nginx calculates from the
> request,
> > before it decides whether to send the response from cache, or
> whether
> > to pass the request to upstream.
> > 
> > > if the upstream_cookie_logged_in value is not equal to 1 how can
> I
> > set
> > > $session_id_value ''; make empty
> > 
> > $upstream_cookie_something is part of the response from upstream,
> > so is not available to nginx at the time that it is calculating
> > fastcgi_cache_key for the "read from cache or not" decision.
> > 
> > Am I missing something?
> > 
> > 	f
> > -- 
> > Francis Daly        francis at daoine.org
> > 
> > _______________________________________________
> > nginx mailing list
> > nginx at nginx.org
> > http://mailman.nginx.org/mailman/listinfo/nginx
> 
> 
> Thanks :) so changes to that value will have no effect.
> 
> What about the following scenario.
> 
> I remove all Set-Cookie headers.
> fastcgi_hide_header Set-Cookie;
> 
> 
> Then add them back in with :
> add_header Set-Cookie "$upstream_http_set_cookie";
> 
> Will requests that get a cache hit ever contain a Set-Cookie header or
> isit only the ones that reach the origin php server.
> 
> From my tests it appears to be working that no set-cookie headers are
> present on "X-Cache-Status : HIT" headers.

With :
fastcgi_hide_header Set-Cookie;

I think i should allow myself to add set-cookie headers to fresh origin
requests like this.

map $upstream_cache_status $upstream_value_status {
~MISS $upstream_http_set_cookie;
~BYPASS $upstream_http_set_cookie;
~EXPIRED $upstream_http_set_cookie;
}
add_header Set-Cookie $upstream_value_status;

I have not tested this yet though.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,269296,269330#msg-269330



More information about the nginx mailing list