<div class="im" style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(34,34,34)">I realized my folly. Set-Cookie for csrf token is invalidating the cache!</span></div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><font color="#222222" face="arial, sans-serif"><br clear="all"></font>- Quintin</div><br><div class="gmail_quote">
On Fri, Oct 19, 2012 at 7:50 AM, Quintin Par <span dir="ltr"><<a href="mailto:quintinpar@gmail.com" target="_blank">quintinpar@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

















<p>
















</p><p>I have my homepage cached as shown </p>

<p class="MsoNormal"><span style="font-size:9.0pt">location
= / {</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  if (-f
/var/www/statichtmls/during_build.html) {</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  return 503;</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  }</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  set $country_code $http_x_country_code;</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  set_if_empty $country_code
$geoip_country_code;</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt"> </span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  limit_req zone=pw burst=5 nodelay;</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  proxy_pass 
<a href="http://localhost:82" target="_blank">http://localhost:82</a>;</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  proxy_set_header   Host             $host;</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  proxy_set_header   X-Real-IP        $remote_addr;</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  proxy_set_header   X-Country-Code   $country_code; </span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  proxy_set_header Accept-Encoding
"";</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  proxy_ignore_headers Cache-Control; </span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  proxy_ignore_headers Expires; </span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  proxy_ignore_headers X-Accel-Expires; </span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  add_header X-Cache-Status
$upstream_cache_status;</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  proxy_cache             cache;</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  proxy_cache_key        
$scheme$host$request_uri$cookie_sessionid$country_code; </span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  proxy_cache_valid       200 302 2m;</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">  proxy_cache_use_stale   updating;</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">}</span></p>

<p>But every time I hit the page as an anonymous user it
shows </p>

<p class="MsoNormal"><span style="font-size:9.0pt">X-Cache-Status:
EXPIRED    </span></p><p class="MsoNormal"><span style="font-size:9.0pt"><br></span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">user$
curl -I <a href="http://site.com" target="_blank">site.com</a></span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">HTTP/1.1
200 OK</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">Server:
ngx_openresty</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">Date:
Fri, 19 Oct 2012 02:15:32 GMT</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">Content-Type:
text/html; charset=utf-8</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">Connection:
keep-alive</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">Keep-Alive:
timeout=60</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">Vary:
Accept-Encoding</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">Vary:
Cookie</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">Set-Cookie:
csrftoken=Dl4mvy4Rky7sfZwqek27hFrCXzWCi9As; expires=Fri, 18-Oct-2013 02:15:32</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt"> GMT; Max-Age=31449600; Path=/</span></p>

<p class="MsoNormal"><span style="font-size:9.0pt">X-Cache-Status:
EXPIRED</span></p>

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

<p>How do I cache the homepage correctly?</p>

<p></p>

</blockquote></div><br>