Multiple caching solutions for anonymous and logged in users with SSI on
Antonio P.P. Almeida
appa at perusio.net
Tue Mar 6 10:01:42 UTC 2012
> Thanks Antonio.
>
> On a side note, if I craft a proxy cache key with cookie_sessionid and if
> the sessionid cookie does not exist, *will nginx take it as an empty
> value*?
Sure. Here's an example using map.
map $http_cookie $cache_id {
default nil; # hommage to Lisp :)
~SESS[[:alnum:]]+=(?<session_id>[[:graph:]]+) $session_id;
}
When there's no SESS cookie then $cache_id is nil.
> Can nginx do a try_files or 'if' on the existence of a cookie? This
> will
> help me deliver two caching strategies in the same location directive.
Sure. Example. At the http level:
map $http_cookie $cookie_exists {
default 0;
~<regex testing cookie> 1;
}
On the "main" cache location:
error_page 418 @other-cache-location;
if ($cookie_exists) {
return 418;
}
Something of this kind will work.
--appa
More information about the nginx
mailing list