fastcgi_cache_key with cookie

António P. P. Almeida appa at
Tue Dec 27 07:34:04 UTC 2011

On 27 Dez 2011 06h53 WET, nginx-forum at wrote:

> Thx for replying, but I have already tried this config from
> With this config it will not cache the page correct?  What I'm
> trying to do is set every page to be cached whether logged in or
> not, or more specifically to maintain a separate cache for each
> user.  But I need to differentiate the cache key based on the
> session cookie.

Why not implement a small module that sets a DRUPAL_UID cookie and use
that as a cache key? Much simpler than using the session cookie.

Take a look at what the boost module does. I can put up a simple
module that does that. Are you on drupal 6/pressflow?

> I need to optimize for authenticated performance, our website has
> 90% logged in users, our non authenticated speed for nginx is more
> than sufficient now.  On my crappy laptop I can get 4000+ req/s for
> non authenticated pages, for authenticated pages I get 2 req/sec
> without any caching at all.  With fastcgi caching I can get 3000+
> req/sec, but this is without google analytics, as soon as I enable
> it my speed plunges down to 2req/sec :(

Ok. Then what you need is a better key. If you have the DRUPAL_UID
cookie then set:

fastcgi_cache_key $http_cookie_DRUPAL_UID$scheme$host$request_uri;

That's a cool idea for a very simple module.

There's a hack here for setting a DRUPAL_UID cookie but it involves
killing kittens: hacking core :)

--- appa

PS: Here's a very simple module that sets a header, not a cookie. It's
    untested YMMV, caveat emptor, and all that:

    The .info file is missing.

PPS: Use this key with the above module.

     fastcgi_cache_key $http_x_drupal_uid$scheme$host$request_uri;

More information about the nginx mailing list