<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>Hi Per Buer,</p>
<p>Thanks for your response and for the tips. Would go through them
and try to implement. <br>
</p>
<p>Regarding the blank pages, I have sent a separate mail. <br>
</p>
<p>I have installed Varnish from source. Since this is the first
time with Varnish, we plan to start with simple scenarios for
caching and then move on to more sophisticated ones for logged in
users etc (also, as we scale up further).<br>
</p>
<p>Would really appreciate if you could help me resolving the issue
so that I could move ahead with configuring and deploying Varnish.
Following is the content of the mail with the issue:</p>
<p>Hi,</p>
<p>I am trying to set Varnish to cache content when login cookie is
not present. Hence, I have modified the following subroutines:</p>
<ul>
<li>vcl_recv: If the login cookie is not present, return hash.</li>
<li>vcl_back_response: If the login cookie is not present, cache
the content (beresp.uncacheable set to false</li>
</ul>
<p>Whenever the vcl_recv is returning hash, varnish is generating
blank page with content-length set 0. If vcl_recv returns pass,
the page is served fine. <br>
</p>
<p>Following is the VCL:</p>
<p>sub vcl_recv {<br>
# Happens before we check if we have this in cache already.<br>
#<br>
# Typically you clean up the request here, removing cookies
you don't need,<br>
# rewriting the request, etc.<br>
set req.backend_hint = uwsgi;<br>
<br>
if (req.http.Cookie !~ "jivaana_user=") {<br>
return(hash);<br>
}<br>
}<br>
<br>
sub vcl_backend_response {<br>
# Happens after we have read the response headers from the
backend.<br>
#<br>
# Here you clean the response headers, removing silly
Set-Cookie headers<br>
# and other mistakes your backend does.<br>
if (beresp.http.Set-Cookie !~ "jivaana_user=") {<br>
if (beresp.ttl <= 0s) {<br>
set beresp.ttl = 120s;<br>
}<br>
set beresp.uncacheable = false;<br>
return (deliver);<br>
}</p>
<p>Varnish log:</p>
<p><br>
</p>
* << BeReq >> 3 <br>
- Begin bereq 2 fetch<br>
- Timestamp Start: 1463994442.986360 0.000000 0.000000<br>
- BereqMethod GET<br>
- BereqURL /catalogue/<br>
- BereqProtocol HTTP/1.0<br>
- BereqHeader Host: django_test<br>
- BereqHeader Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8<br>
- BereqHeader Upgrade-Insecure-Requests: 1<br>
- BereqHeader User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS
X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/50.0.2661.102 Safari/537.36<br>
- BereqHeader Accept-Language: en-US,en;q=0.8<br>
- BereqHeader X-Forwarded-For: 127.0.0.1<br>
- BereqHeader Accept-Encoding: gzip<br>
- BereqProtocol HTTP/1.1<br>
- BereqHeader X-Varnish: 3<br>
- VCL_call BACKEND_FETCH<br>
- VCL_return fetch<br>
- BackendOpen 21 boot.uwsgi 127.0.0.1 9001 127.0.0.1 38213<br>
- Timestamp Bereq: 1463994442.986883 0.000524 0.000524<br>
- Timestamp Beresp: 1463994443.734972 0.748612 0.748088<br>
- BerespProtocol HTTP/1.1<br>
- BerespStatus 200<br>
- BerespReason OK<br>
- BerespHeader Expires: Mon, 23 May 2016 09:07:23 GMT<br>
- BerespHeader Vary: Cookie<br>
- BerespHeader Last-Modified: Mon, 23 May 2016 09:07:23 GMT<br>
- BerespHeader Cache-Control: max-age=0<br>
- BerespHeader X-Frame-Options: SAMEORIGIN<br>
- BerespHeader Content-Type: text/html; charset=utf-8<br>
- BerespHeader Set-Cookie:
csrftoken=5BUZRL4gdO7uTDtWXnbqQko3CelDmOAg; expires=Mon, 22-May-2017
09:07:23 GMT; Max-Age=31449600; Path=/<br>
- BerespHeader Date: Mon, 23 May 2016 09:07:23 GMT<br>
- TTL RFC 0 10 -1 1463994444 1463994444 1463994443
1463994443 0<br>
- VCL_call BACKEND_RESPONSE<br>
- TTL VCL 120 10 0 1463994444<br>
- VCL_return deliver<br>
- Storage file s0<br>
- ObjProtocol HTTP/1.1<br>
- ObjStatus 200<br>
- ObjReason OK<br>
- ObjHeader Expires: Mon, 23 May 2016 09:07:23 GMT<br>
- ObjHeader Vary: Cookie<br>
- ObjHeader Last-Modified: Mon, 23 May 2016 09:07:23 GMT<br>
- ObjHeader Cache-Control: max-age=0<br>
- ObjHeader X-Frame-Options: SAMEORIGIN<br>
- ObjHeader Content-Type: text/html; charset=utf-8<br>
- ObjHeader Set-Cookie:
csrftoken=5BUZRL4gdO7uTDtWXnbqQko3CelDmOAg; expires=Mon, 22-May-2017
09:07:23 GMT; Max-Age=31449600; Path=/<br>
- ObjHeader Date: Mon, 23 May 2016 09:07:23 GMT<br>
- Fetch_Body 0 none -<br>
- BackendReuse 21 boot.uwsgi<br>
- Timestamp BerespBody: 1463994443.735229 0.748869 0.000257<br>
- Length 0<br>
- BereqAcct 393 0 393 336 0 336<br>
- End <br>
<br>
* << Request >> 2 <br>
- Begin req 1 rxreq<br>
- Timestamp Start: 1463994442.986091 0.000000 0.000000<br>
- Timestamp Req: 1463994442.986091 0.000000 0.000000<br>
- ReqStart 127.0.0.1 56147<br>
- ReqMethod GET<br>
- ReqURL /catalogue/<br>
- ReqProtocol HTTP/1.0<br>
- ReqHeader Host: django_test<br>
- ReqHeader Connection: close<br>
- ReqHeader Cache-Control: max-age=0<br>
- ReqHeader Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8<br>
- ReqHeader Upgrade-Insecure-Requests: 1<br>
- ReqHeader User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS
X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/50.0.2661.102 Safari/537.36<br>
- ReqHeader Accept-Encoding: gzip, deflate, sdch<br>
- ReqHeader Accept-Language: en-US,en;q=0.8<br>
- ReqHeader Cookie: pagemap=0,0,0,0,0,1,0';
pagemap=0,0,0,0,0,0,0; jivaana_country=IN; mp_mixpanel__c=1;
mp_mixpanel__c3=2; mp_mixpanel__c4=2; mp_mixpanel__c5=0;
_ga=GA1.1.1762020660.1447765749;
mp_774636c1ed2371eaf99455f71871069c_mixpanel=%7B%22distinct_id%22%3A%20<br>
- ReqHeader If-Modified-Since: Mon, 23 May 2016 09:03:11 GMT<br>
- ReqHeader X-Forwarded-For: 127.0.0.1<br>
- VCL_call RECV<br>
- ReqUnset Cookie: pagemap=0,0,0,0,0,1,0';
pagemap=0,0,0,0,0,0,0; jivaana_country=IN; mp_mixpanel__c=1;
mp_mixpanel__c3=2; mp_mixpanel__c4=2; mp_mixpanel__c5=0;
_ga=GA1.1.1762020660.1447765749;
mp_774636c1ed2371eaf99455f71871069c_mixpanel=%7B%22distinct_id%22%3A%20<br>
- VCL_return hash<br>
- ReqUnset Accept-Encoding: gzip, deflate, sdch<br>
- ReqHeader Accept-Encoding: gzip<br>
- VCL_call HASH<br>
- VCL_return lookup<br>
- VCL_call MISS<br>
- VCL_return fetch<br>
- Link bereq 3 fetch<br>
- Timestamp Fetch: 1463994443.735287 0.749196 0.749196<br>
- RespProtocol HTTP/1.1<br>
- RespStatus 200<br>
- RespReason OK<br>
- RespHeader Expires: Mon, 23 May 2016 09:07:23 GMT<br>
- RespHeader Vary: Cookie<br>
- RespHeader Last-Modified: Mon, 23 May 2016 09:07:23 GMT<br>
- RespHeader Cache-Control: max-age=0<br>
- RespHeader X-Frame-Options: SAMEORIGIN<br>
- RespHeader Content-Type: text/html; charset=utf-8<br>
- RespHeader Set-Cookie:
csrftoken=5BUZRL4gdO7uTDtWXnbqQko3CelDmOAg; expires=Mon, 22-May-2017
09:07:23 GMT; Max-Age=31449600; Path=/<br>
- RespHeader Date: Mon, 23 May 2016 09:07:23 GMT<br>
- RespHeader X-Varnish: 2<br>
- RespHeader Age: 0<br>
- RespHeader Via: 1.1 varnish-v4<br>
- VCL_call DELIVER<br>
- VCL_return deliver<br>
- Timestamp Process: 1463994443.735341 0.749249 0.000054<br>
- RespHeader Accept-Ranges: bytes<br>
- RespHeader Content-Length: 0<br>
- Debug "RES_MODE 2"<br>
- RespHeader Connection: close<br>
- Timestamp Resp: 1463994443.735410 0.749319 0.000070<br>
- ReqAcct 929 0 929 476 0 476<br>
- End <br>
<br>
* << Session >> 1 <br>
- Begin sess 0 HTTP/1<br>
- SessOpen 127.0.0.1 56147 0.0.0.0:9003 127.0.0.1 9003
1463994442.985890 18<br>
- Link req 2 rxreq<br>
- SessClose RESP_CLOSE 0.750<br>
- End <br>
<br>
Thanks,<br>
Pinakee<br>
<div class="moz-cite-prefix">On 23/05/16 11:21 pm, Per Buer wrote:<br>
</div>
<blockquote
cite="mid:CAOXZevD+gBcsPCna7DUsmDF1dd=s9pELNbNxOHJG0k0S9JHANw@mail.gmail.com"
type="cite">
<div dir="ltr"><br>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Fri, May 20, 2016 at 4:38 PM,
Pinakee BIswas <span dir="ltr"><<a
moz-do-not-send="true" href="mailto:pinakee@waltzz.com"
target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:pinakee@waltzz.com">pinakee@waltzz.com</a></a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
I am a beginner with Varnish and planning to deploy it for
our ecommerce live platform. I am trying to learn Varnish
and VCL and having trouble for our specific scenario:<br>
<br>
I would like to cache pages when a user is not logged in -
and this is determined by a cookie (which is standard).
The ecommerce platform is based on python Django - and
there are bunch of other cookies which are not relevant
for caching but they can't be unset/removed as they are
needed by the origin/backend server.<br>
<br>
Hence, the solution would be to check if the login cookie
is present or not. If login cookie not present, cache the
page and fetch from cache else pass it to the backend.<br>
</blockquote>
<div><br>
</div>
<div>Two tips. One is the cookie VMOD, which helps when
dealing with cookies. If you don't wanna use it you can
also look at the example here: <a moz-do-not-send="true"
href="https://www.varnish-cache.org/docs/4.1/users-guide/increasing-your-hitrate.html#cookies">https://www.varnish-cache.org/docs/4.1/users-guide/increasing-your-hitrate.html#cookies</a>
- it will at least point you in the right direction.</div>
<div><br>
</div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">I
tried implementing the above logic in vcl_recv and
vcl_backend_response with my limited knowledge, but
varnish started serving blank pages.<br>
</blockquote>
<div><br>
</div>
<div>That sounds like a backend bug.</div>
<div><br>
</div>
</div>
-- <br>
<div class="gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<table
style="border-bottom-width:1px;padding-top:5px;border-top-style:solid;width:550px;padding-bottom:5px;border-bottom-color:rgb(238,238,238);border-top-width:1px;border-bottom-style:solid;line-height:1.5em;border-top-color:rgb(238,238,238);color:rgb(102,102,102);font-size:12px;font-family:'Helvetica
Neue',Arial,sans-serif;margin-top:20px" border="0"
cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td width="100"><img moz-do-not-send="true"
src="http://www.varnish-software.com/static/media/logo-email.png"></td>
<td><font color="#222222"><span
style="font-size:14px"><b>Per Buer</b></span></font><br>
CTO | Varnish Software AS<br>
Cell: <a moz-do-not-send="true"
value="+4790181750"
style="color:rgb(17,85,204)">+47 95839117</a><br>
<span style="font-weight:bold">We Make
Websites Fly!<br>
<a moz-do-not-send="true"
href="https://www.varnish-software.com/"
style="color:rgb(17,85,204)"
target="_blank">www.varnish-software.com</a></span></td>
</tr>
</tbody>
</table>
<br>
<div style="color:rgb(136,136,136)"><a
moz-do-not-send="true"
href="http://info.varnish-software.com/signature"
target="_blank"><img moz-do-not-send="true"
src="http://files.varnish-software.com/signature.png"></a><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<br>
</body>
</html>