fastcgi_cache_key with cookie

zenw nginx-forum at
Tue Dec 27 07:46:28 UTC 2011

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

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_cache        tmpcache;
            proxy_cache_key    $uri$is_args$args;

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

not sure how to rewrite the url.

Posted at Nginx Forum:,220510,220520#msg-220520

More information about the nginx mailing list