# Fastcgi\_cache\_key with cookie

**URL:** <https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216>\
**Category:** NGINX\
**Created:** [December 27, 2011, 6:14am UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216 "2011-12-27T06:14:19Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [December 27, 2011, 6:14am UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/1 "2011-12-27T06:14:19Z")

</div>

I’m trying to cache per user Drupal using this config :

fastcgi\_ignore\_headers Cache-Control Expires; #tried ‘\_\_utma’  
‘Set-Cookie’  
fastcgi\_cache drupal;  
fastcgi\_cache\_key $http\_cookie$request\_method$scheme$host$request\_uri;  
fastcgi\_cache\_methods GET HEAD;  
fastcgi\_cache\_valid any 1s;  
fastcgi\_cache\_use\_stale error timeout invalid\_header updating http\_500;

fastcgi\_max\_temp\_file\_size 2M;  
add\_header X-Micro-Cache $upstream\_cache\_status;

I can get this working without google analytics, but when I enable  
google analytics it adds several cookies \_\_utma \_\_utmb \_\_utmc \_\_utmz.  
Nginx looks at $http\_cookie and sees that its different so it passes it  
to the backend. Preferably I would like to just use the cache key as  
$cookie\_SESS which is the drupal session cookie, however the full cookie  
name is encoded to something like this

SSESSae42ac488e03c2e2xxxxxda6ce2f5ee7=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I’ve omitted some letters and numbers. So my question is how do I just  
extract the Drupal Session cookie? Or failing that just strip all  
cookies? I have tried fastcgi\_ignore header ‘\_\_utma’ ‘Set-Cookie’ but  
it doesn’t seem to work.

Posted at Nginx Forum:

> **[fastcgi\_cache\_key with cookie](https://forum.nginx.org/read.php?2,220510,220510#msg-220510)**
>
> I'm trying to cache per user Drupal using this config : fastcgi\_ignore\_headers Cache-Control Expires; #tried '\_\_utma' 'Set-Cookie' fastcgi\_cache drupal; fastcgi\_cache\_key $http\_cookie$request\_method$scheme$host$request\_uri; fastcgi\_cache\_methods GET...

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 27, 2011, 7:38am UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/2 "2011-12-27T07:38:04Z")

</div>

On 27 Dez 2011 05h13 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m trying to cache per user Drupal using this config :
> 
> fastcgi\_ignore\_headers Cache-Control Expires; #tried ‘\_\_utma’  
> ‘Set-Cookie’  
> fastcgi\_cache drupal;  
> fastcgi\_cache\_key $http\_cookie$request\_method$scheme$host$request\_uri;  
> fastcgi\_cache\_methods GET HEAD;  
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
> This is not needed. This is the _default_ setting. Cf.  
> [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpFcgiModule#fastcgi_cache_methods)

> fastcgi\_cache\_valid any 1s;  
> fastcgi\_cache\_use\_stale error timeout invalid\_header updating http\_500;
> 
> fastcgi\_max\_temp\_file\_size 2M;  
> add\_header X-Micro-Cache $upstream\_cache\_status;

> I can get this working without google analytics, but when I enable  
> google analytics it adds several cookies \_\_utma \_\_utmb \_\_utmc  
> \_\_utmz. Nginx looks at $http\_cookie and sees that its different so  
> it passes it to the backend. Preferably I would like to just use  
> the cache key as
> 
> > cookie\_SESS which is the drupal session cookie, however the full  
> > cookie  
> > name is encoded to something like this

> SSESSae42ac488e03c2e2xxxxxda6ce2f5ee7=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Remove that key and replace by:

fastcgi\_cache\_key $scheme$host$request\_uri;

At the http level do:

map $http\_cookie $no\_cache {  
default 0;  
~SESS 1;  
}

Then add:

## If we have a cookie we should bypass the cache. The same if we have a

fastcgi\_cache\_bypass $no\_cache;  
fastcgi\_no\_cache $no\_cache;

To the above FCGI cache config.

Also the first stop for drupal and Nginx stuff is the g.d.o group 😉

[http://groups.drupal.org/nginx](http://groups.drupal.org/nginx)

— appa

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 27, 2011, 7:54am UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/3 "2011-12-27T07:54:04Z")

</div>

Thx for replying, but I have already tried this config from [drupal.org](http://drupal.org).

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.

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 ☹

Posted at Nginx Forum:

> **[Re: fastcgi\_cache\_key with cookie](https://forum.nginx.org/read.php?2,220510,220513#msg-220513)**
>
> I'm trying to cache per user Drupal using this config : fastcgi\_ignore\_headers Cache-Control Expires; #tried '\_\_utma' 'Set-Cookie' fastcgi\_cache drupal; fastcgi\_cache\_key $http\_cookie$request\_method$scheme$host$request\_uri; fastcgi\_cache\_methods GET...

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 27, 2011, 7:57am UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/4 "2011-12-27T07:57:08Z")

</div>

Oh you are Perusio 😛 I got your config from [drupal.org](http://drupal.org) hehe 😛 and  
tried your drupal-with-nginx config from github 😛

Posted at Nginx Forum:

> **[Re: fastcgi\_cache\_key with cookie](https://forum.nginx.org/read.php?2,220510,220514#msg-220514)**
>
> I'm trying to cache per user Drupal using this config : fastcgi\_ignore\_headers Cache-Control Expires; #tried '\_\_utma' 'Set-Cookie' fastcgi\_cache drupal; fastcgi\_cache\_key $http\_cookie$request\_method$scheme$host$request\_uri; fastcgi\_cache\_methods GET...

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 27, 2011, 8:34am UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/5 "2011-12-27T08:34:46Z")

</div>

On 27 Dez 2011 06h53 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thx for replying, but I have already tried this config from  
> [drupal.org](http://drupal.org).
> 
> 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 🙂

[http://groups.drupal.org/node/194333](http://groups.drupal.org/node/194333)

— appa

PS: Here’s a very simple module that sets a header, not a cookie. It’s  
untested YMMV, caveat emptor, and all that:  
[Simple module to add a header with the user ID · GitHub](https://gist.github.com/1522957)

```
The .info file is missing.

```

PPS: Use this key with the above module.

```
 fastcgi_cache_key $http_x_drupal_uid$scheme$host$request_uri;

```

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 27, 2011, 8:47am UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/6 "2011-12-27T08:47:08Z")

</div>

I’ve also tried this using the userid module I set a custom cookie like  
so

userid on;  
userid\_name “testid”;  
userid\_expires 100s;

and set the fastcgi\_cache\_key like so

fastcgi\_cache\_key $cookie\_testid$request\_method$scheme$host$request\_uri

the problem with this setup is when I login or logout, since the key is  
based on only $cookie\_testid without $http\_cookie, then the user will  
still see the logged in page even after logging out. Alternatively how  
would I user the cache purge module to purge the key when the user hits  
the login or logout button? this is the sample config

http {  
proxy\_cache\_path /tmp/cache keys\_zone=tmpcache:10m;

```
server {
    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_cache tmpcache;
        proxy_cache_key $uri$is_args$args;
    }

    location ~ /purge(/.*) {
        allow 127.0.0.1;
        deny all;
        proxy_cache_purge tmpcache $1$is_args$args;
    }
}

```

}

not sure how to rewrite the url.

Posted at Nginx Forum:

> **[Re: fastcgi\_cache\_key with cookie](https://forum.nginx.org/read.php?2,220510,220520#msg-220520)**
>
> I'm trying to cache per user Drupal using this config : fastcgi\_ignore\_headers Cache-Control Expires; #tried '\_\_utma' 'Set-Cookie' fastcgi\_cache drupal; fastcgi\_cache\_key $http\_cookie$request\_method$scheme$host$request\_uri; fastcgi\_cache\_methods GET...

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 27, 2011, 9:01am UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/7 "2011-12-27T09:01:57Z")

</div>

On 27 Dez 2011 07h46 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> $cookie\_testid$request\_method$scheme$host$request\_uri
> 
> the problem with this setup is when I login or logout, since the key  
> is based on only $cookie\_testid without $http\_cookie, then the user  
> will still see the logged in page even after logging out.  
> Alternatively how would I user the cache purge module to purge the  
> key when the user hits the login or logout button? this is the  
> sample config

I think you can do it with map. Untested:

map $http\_cookie $logged\_in {  
default 0;  
~SESS 1;  
}

Define two locations each with a different cache (anon/authenticated):

The default cache is the anon:

location @anon-cache {  
error\_page 418 @auth-cache;  
if ($logged\_in) {  
return 418;  
}  
userid\_expires 0s;  
… # fastcgi cache stuff for anon users  
}

location @auth-cache {  
# set the user id expires here to a positive value  
# fastcgi cache for authenticated users  
}

I never played with the userid module. So…

— appa

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 27, 2011, 9:24am UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/8 "2011-12-27T09:24:48Z")

</div>

Sorry I dont quite understand whats going on in your config.

error\_page 418 @auth-cache;  
if ($logged\_in) {  
return 418;

what does this do? looked up http error 418 “I’m a teapot” ROFL. so  
going line by line

Posted at Nginx Forum:

> **[Re: fastcgi\_cache\_key with cookie](https://forum.nginx.org/read.php?2,220510,220524#msg-220524)**
>
> I'm trying to cache per user Drupal using this config : fastcgi\_ignore\_headers Cache-Control Expires; #tried '\_\_utma' 'Set-Cookie' fastcgi\_cache drupal; fastcgi\_cache\_key $http\_cookie$request\_method$scheme$host$request\_uri; fastcgi\_cache\_methods GET...

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 27, 2011, 8:48am UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/9 "2011-12-27T08:48:59Z")

</div>

I suppose when the user hits login or logout button the url needs to be

[http://example.com/purge](http://example.com/purge)

if my default logged in page is [http://example.com/](http://example.com/)

Posted at Nginx Forum:

> **[Re: fastcgi\_cache\_key with cookie](https://forum.nginx.org/read.php?2,220510,220521#msg-220521)**
>
> I'm trying to cache per user Drupal using this config : fastcgi\_ignore\_headers Cache-Control Expires; #tried '\_\_utma' 'Set-Cookie' fastcgi\_cache drupal; fastcgi\_cache\_key $http\_cookie$request\_method$scheme$host$request\_uri; fastcgi\_cache\_methods GET...

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 27, 2011, 10:06am UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/10 "2011-12-27T10:06:12Z")

</div>

On 27 Dez 2011 08h24 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Sorry I dont quite understand whats going on in your config.
> 
> error\_page 418 @auth-cache;  
> if ($logged\_in) {  
> return 418;
> 
> what does this do? looked up http error 418 “I’m a teapot” ROFL.  
> so going line by line

Yes, hence it’s innocuous to use 🙂 You get to keep all other for real  
status codes.

The map sets the value of the $logged\_in variable. If there’s a cookie  
with SESS it sets it to 1. The default is 0.

If $logged\_in is 1 then return a 418. The error\_page directive sets  
the 418 error page to be the @auth-cache location.

— appa

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 27, 2011, 6:02pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/11 "2011-12-27T18:02:10Z")

</div>

## zenw Wrote:

> fastcgi\_cache\_valid any 1s;  
> to just use the cache key as $cookie\_SESS which is  
> ‘\_\_utma’ ‘Set-Cookie’ but it doesn’t seem to work.  
> Maybe extract the session cookie with something like this:

map $http\_cookie $session\_cookie {  
default “”;  
~^._(?SESS.+;)._$ $key;  
}

and

fastcgi\_cache\_key  
$session\_cookie$request\_method$scheme$host$request\_uri;

I’m sure the regex could be written better, but that does work.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,220510,220559#msg-220559](http://forum.nginx.org/read.php?2,220510,220559#msg-220559)

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 28, 2011, 2:16am UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/12 "2011-12-28T02:16:05Z")

</div>

Awesome this works great, thanks so much for your help dude!! 🙂

Posted at Nginx Forum:

> **[Re: fastcgi\_cache\_key with cookie](https://forum.nginx.org/read.php?2,220510,220565#msg-220565)**
>
> I'm trying to cache per user Drupal using this config : fastcgi\_ignore\_headers Cache-Control Expires; #tried '\_\_utma' 'Set-Cookie' fastcgi\_cache drupal; fastcgi\_cache\_key $http\_cookie$request\_method$scheme$host$request\_uri; fastcgi\_cache\_methods GET...

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 28, 2011, 2:35am UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/13 "2011-12-28T02:35:48Z")

</div>

Oh and your too brian mercer, you have been a great help with all your  
useful articles on nginx and drupal 😛

Posted at Nginx Forum:

> **[Re: fastcgi\_cache\_key with cookie](https://forum.nginx.org/read.php?2,220510,220566#msg-220566)**
>
> I'm trying to cache per user Drupal using this config : fastcgi\_ignore\_headers Cache-Control Expires; #tried '\_\_utma' 'Set-Cookie' fastcgi\_cache drupal; fastcgi\_cache\_key $http\_cookie$request\_method$scheme$host$request\_uri; fastcgi\_cache\_methods GET...

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 28, 2011, 5:15am UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/14 "2011-12-28T05:15:52Z")

</div>

## António P. P. Almeida Wrote:

> > > fastcgi\_ignore\_headers Cache-Control Expires;  
> > > fastcgi\_max\_temp\_file\_size 2M;  
> > > it  
> > > xxxxxxxxxxxxxxxxxx  
> > > like this:  
> > > map $http\_cookie $session\_id {  
> > > default ‘’;  
> > > ~SESS(?\<session\_guid\>[[:alnum:]]+)  
> > > $session\_guid;  
> > > }
> 
> — appa

That regex will only get you the cookie name (md5 of domain) without the  
cookie value. You will want the equal sign in there so you get both  
name and value:

~^._SESS(?[\w=]+)._$ $key;

or just the value:

~^._SESS.+=(?[\w]+)._$ $key;

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,220510,220568#msg-220568](http://forum.nginx.org/read.php?2,220510,220568#msg-220568)

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 27, 2011, 8:52pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/15 "2011-12-27T20:52:55Z")

</div>

On 27 Dez 2011 17h01 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > i;  
> > at $http\_cookie and sees that its different so it  
> > Session cookie? Or failing that just strip all  
> > cookies? I have tried fastcgi\_ignore header  
> > ‘\_\_utma’ ‘Set-Cookie’ but it doesn’t seem to work.
> 
> Maybe extract the session cookie with something like this:
> 
> map $http\_cookie $session\_cookie {  
> default “”;  
> ~^._(?SESS.+;)._$ $key;  
> }

Yes. We can remove the SESS string and keep just the unique part of the  
id.

map $http\_cookie $session\_id {  
default ‘’;  
~SESS(?\<session\_guid\>[[:alnum:]]+) $session\_guid;  
}

— appa

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 28, 2011, 5:29am UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/16 "2011-12-28T05:29:25Z")

</div>

Many thanks Perusio 😛

Posted at Nginx Forum:

> **[Re: fastcgi\_cache\_key with cookie](https://forum.nginx.org/read.php?2,220510,220569#msg-220569)**
>
> I'm trying to cache per user Drupal using this config : fastcgi\_ignore\_headers Cache-Control Expires; #tried '\_\_utma' 'Set-Cookie' fastcgi\_cache drupal; fastcgi\_cache\_key $http\_cookie$request\_method$scheme$host$request\_uri; fastcgi\_cache\_methods GET...

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 28, 2011, 8:03am UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/17 "2011-12-28T08:03:26Z")

</div>

On 28 Dez 2011 04h15 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> the cookie value. You will want the equal sign in there so you get  
> both name and value:
> 
> ~^._SESS(?[\w=]+)._$ $key;
> 
> or just the value:
> 
> ~^._SESS.+=(?[\w]+)._$ $key;

MD5 of the domain? How? AFAIK it’s much more elaborate than that.

See:  
[http://svn.php.net/viewvc/php/php-src/branches/PHP\_5\_3\_8/ext/session/session.c?revision=315335&view=markup](http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3_8/ext/session/session.c?revision=315335&view=markup)

— appa

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 28, 2011, 2:56pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/18 "2011-12-28T14:56:04Z")

</div>

## António P. P. Almeida Wrote:

> > > — appa  
> > > or just the value:
> 
> — appa
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

Drupal session cookie is in the form:  
session\_name = session\_id  
e.g.  
SESSc4f381f0375dba8f9670647c311307a9=b051bb99415e65d3d921f7891f3ca91f

The session\_name is either  
session\_name(‘SESS’ . md5($cookie\_domain))  
from your settings file or  
session\_name(‘SESS’ . md5(explode(‘://’, $base\_url, 2)))  
see

> **[drupal 11.x | Drupal API](https://api.drupal.org/api/drupal/includes--bootstrap.inc/function/conf_init/6.x)**

Your regex was only getting the session\_name and not the session\_id

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,220510,220596#msg-220596](http://forum.nginx.org/read.php?2,220510,220596#msg-220596)

---

<div class="post-metadata">

**Author:** ![zenw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/aca169/32.png) [@zenw](https://www.ruby-forum.com/u/zenw)\
**Post date:** [December 28, 2011, 5:53pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-key-with-cookie/215216/19 "2011-12-28T17:53:32Z")

</div>

On 28 Dez 2011 13h55 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > > }  
> > > > ~^._SESS(?[\w=]+)._$ $key;  
> > > > \_5\_3\_8/ext/session/session.c?revision=315335&view=  
> > > > SESSc4f381f0375dba8f9670647c311307a9=b051bb99415e65d3d921f7891f3ca91f
> 
> The session\_name is either session\_name(‘SESS’  
> . md5($cookie\_domain)) from your settings file or  
> session\_name(‘SESS’ . md5(explode(‘://’, $base\_url, 2))) see  
> [Client Challenge](http://api.drupal.org/api/drupal/includes--bootstrap.inc/function/conf_init/6)
> 
> Your regex was only getting the session\_name and not the session\_id

If that’s the case then why get the cookie name? Just get the value  
which is the session ID.

map $http\_cookie $session\_id {  
default ‘’;  
~SESS[[:alnum:]]+=(?\<session\_guid\>[[:alnum:]]+) $session\_guid;  
}

— appa
