Cache always shows expired status for anonymous users

Quintin Par quintinpar at
Fri Oct 19 02:20:25 UTC 2012

I have my homepage cached as shown

location = / {

  if (-f /var/www/statichtmls/during_build.html) {

  return 503;


  set $country_code $http_x_country_code;

  set_if_empty $country_code $geoip_country_code;

  limit_req zone=pw burst=5 nodelay;

  proxy_pass  http://localhost:82;

  proxy_set_header   Host             $host;

  proxy_set_header   X-Real-IP        $remote_addr;

  proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

  proxy_set_header   X-Country-Code   $country_code;

  proxy_set_header Accept-Encoding "";

  proxy_ignore_headers Cache-Control;

  proxy_ignore_headers Expires;

  proxy_ignore_headers X-Accel-Expires;

  add_header X-Cache-Status $upstream_cache_status;

  proxy_cache             cache;


  proxy_cache_valid       200 302 2m;

  proxy_cache_use_stale   updating;


But every time I hit the page as an anonymous user it shows

X-Cache-Status: EXPIRED

user$ curl -I

HTTP/1.1 200 OK

Server: ngx_openresty

Date: Fri, 19 Oct 2012 02:15:32 GMT

Content-Type: text/html; charset=utf-8

Connection: keep-alive

Keep-Alive: timeout=60

Vary: Accept-Encoding

Vary: Cookie

Set-Cookie: csrftoken=Dl4mvy4Rky7sfZwqek27hFrCXzWCi9As; expires=Fri,
18-Oct-2013 02:15:32

 GMT; Max-Age=31449600; Path=/

X-Cache-Status: EXPIRED

I want to cache it both for logged in and anonymous and it looks like the
absence of session cookie is creating issues.

How do I cache the homepage correctly?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list