Help: cache or not by cookie

tonyy nginx-forum at nginx.us
Sat Jun 20 14:54:57 MSD 2009


The requirement is:

When a cookie exist, not return cached file and not cache the response, if the cookie not exist, return cached file and . cache the response.

In the past, we use a standalone cacheserver, the configuration looks like below:

location / {
  if ($http_cookie ~* xxx ) {
    set  $cache  0;
  }

  if ($cache = 1) {
      proxy_pass  http://cacheserver;
      break;
  }
}

location ~* \.php {
  fastcgi_pass   127.0.0.1:8080;
}

So, cookie-non-exist visit will be directed to cacheserver, and cookie-exist visit will be directed to fastcgi_pass.

So if we want to remove the cacheserver, and use nginx's cache feature, we need to configure like this:

location ~* \.php {
  fastcgi_pass   127.0.0.1:8080;
  fastcgi_cache   php;
  fastcgi_cache_key $request_uri;
}

Then how can we set cookie-non-exist visits to use cache and  cookie-exist visit not to use cache?

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,3173,3173#msg-3173






More information about the nginx mailing list