Reverse Proxy Cache Setup

Ryan Malayter malayter at
Mon Mar 29 21:06:47 MSD 2010

On Mon, Mar 29, 2010 at 11:44 AM, royo <nginx-forum at> wrote:
> Thanks Ryan. I don't have much control over the application itself, so I guess I'd need to enforce the caching somehow for users that are logged in and disable it for those that aren't from nginx.

If you include a unique string in your nginx proxy_cache_key, then
logged-in user requests should never be in cache (again, assuming the
back-end sets cache-control headers).

So, assuming you have "proxy_cache_key
$http_host$request_uri$http_cookie_logmein" in your nginx config:

A request for from an anonymous user would
get nginx cache key:   <-- logmein is empty
This result could be served from cache for future anonymous requests

A request for from a a logged in user user
would get nginx cache key:   <-- logmein
contains user's session ID
In this case, there would not be a cache hit on the nginx side, and a
logged in user's request is passed to the back-end and they get a
customized version of the page. No anonymous users would ever see that
because they don't have that session ID. Presumably, the back-end must
set "Cache-Control: private" or "Cache-Control: no-cache" for
logged-in users. If it doesn't, you're really going to have problems.

I do not think that nginx proxy directives are allowed inside an "if"
block. You might be able to use "if $http_cookie_logmein" to redirect
internally to a named nginx location that does not have any caching.

Can you post your nginx configuration?


More information about the nginx mailing list