Disable Cookies Caching?


I just set up Nginx as a proxy to Apache for my vBulletin based site.
Everything went well till I enabled Nginx caching. Once Nginx caching
is enabled I’m and all users are no longer unable to log-in to the
forum due cookie cashing. When I disable caching we are all able to
log-in as usual.

Is there anyway to completely disable caching for cookies/sessions and
keep caching for anything else?

Here are my settings for Nginx caching:

log_format cache '***$time_local ’
'$upstream_cache_status ’
'Cache-Control: $upstream_http_cache_control ’
'Expires: $upstream_http_expires ’
'"$request" ($status) ’
'"$http_user_agent" ';
access_log /var/log/nginx/cache.access.log cache;
proxy_cache_path /var/www/cache levels=1:2 keys_zone=my-cache:8m
max_size=1000m inactive=7d;
proxy_temp_path /var/www/cache/tmp;
proxy_buffering on;
proxy_cache my-cache;
proxy_cache_valid 200 302 304 10m;
proxy_cache_valid 301 1h;
proxy_cache_valid 404 1m;
proxy_cache_valid any 1m;

Also although there are already some caching in the folder
/var/www/cache, the cache.access.log is empty and has no records in
it, any idea why is that?


On Wed, Jun 23, 2010 at 12:55 AM, MuFei [email protected] wrote:

max_size=1000m inactive=7d;
/var/www/cache, the cache.access.log is empty and has no records in
it, any idea why is that?

It seems proxy_cache_key is set to default, meaning that the cookie is
not included. So everyone will see the same cached responses for GET
requests, whether they log in or not.

try something like:
proxy_cache_key “$host$request_uri$cookie_sessioncookie”;
where “user” is replaced with whatever your session cookie is.

This still may not be usable, though, as you have things configured to
cache all pages for at least 1 minute. That means users will
potentially make a post and then not see any change in the forum
pages. If the forum pages need to be truly dynamic, caching for logged
in users might not be an option.



I’ve tested a while ago only to guest users.
The way i did it (I’m not using anymore) was creating a plugin in global
start with a similar code:

vbsetcookie(‘usercache’, $vbulletin->userinfo[‘userid’], permanent);

Now you should have a new cookie name bbusercache to play with
proxy_cache_key like indicated before.

Note that forums are very dynamic and didn’t made any tests.

Posted at Nginx Forum: