<div dir="ltr"><div>Every one, I'm a newbie for varnish and I need your help. <br><br>My varnish has an strange problem. It create different hash for same url for different client, and this result in any new user which access my site can't hit the cache.<br>
<br>From the varnish log, I found the varnish hit different object though the hash data is same. Following are the logs.<br><br><b><br>Varnish Log From Client 1 (192.168.66.81)</b><br><br> 1 14 StatSess c 192.168.66.81 49278 0 1 0 0 0 0 0 0<br>
2 11 SessionOpen c 192.168.66.81 49300 :80<br> 3 11 ReqStart c 192.168.66.81 49300 1750481507<br> 4 11 RxRequest c GET<br> 5 11 RxURL c /Mainpage<br> 6 11 RxProtocol c HTTP/1.1<br> 7 11 RxHeader c Host: <a href="http://zh.moegirl.org">zh.moegirl.org</a><br>
8 11 RxHeader c Connection: keep-alive<br> 9 11 RxHeader c Cache-Control: max-age=0<br> 10 11 RxHeader c Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8<br> 11 11 RxHeader c User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36<br>
12 11 RxHeader c Accept-Encoding: gzip,deflate,sdch<br> 13 11 RxHeader c Accept-Language: en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4<br> 14 11 RxHeader c Cookie: __utma=1.51232645.1400082743.1400082743.1400082743.1; __utmb=1.1.10.1400082743; __utmc=1; __utmz=1.1400082743.1.1. utmcsr=(direct)|utmccn=(direct)|utmcmd=(<br>
15 none); __gads=ID=d1f7dc9d52cd4a78:T=1400082743:S=ALNI_MbXhSNK0VtcUY7M9mjv8nanysdcbg<br> 16 11 VCL_call c recv lookup<br> 17 11 VCL_call c hash<br> 18 11 Hash c /Mainpage<br> 19 11 Hash c <a href="http://zh.moegirl.org">zh.moegirl.org</a><br>
20 11 VCL_return c hash<br> 21 11 Hit c 1750481502<br> 22 11 VCL_call c hit deliver<br> 23 11 VCL_call c deliver deliver<br> 24 11 TxProtocol c HTTP/1.1<br> 25 11 TxStatus c 200<br>
26 11 TxResponse c OK<br> 27 11 TxHeader c Server: nginx/1.6.0<br> 28 11 TxHeader c Content-Type: text/html; charset=UTF-8<br> 29 11 TxHeader c Vary: Accept-Encoding, Accept-Encoding, Cookie, Accept-Language<br>
30 11 TxHeader c X-Content-Type-Options: nosniff<br> 31 11 TxHeader c Content-language: zh<br> 32 11 TxHeader c Cache-Control: s-maxage=2678400, must-revalidate, max-age=0<br> 33 11 TxHeader c Last-Modified: Mon, 12 May 2014 20:01:11 GMT<br>
34 11 TxHeader c Content-Encoding: gzip<br> 35 11 TxHeader c X-Varnish: 1594679620<br> 36 11 TxHeader c Via: 1.1 varnish<br> 37 11 TxHeader c X-Cache: MISS<br> 38 11 TxHeader c host: <a href="http://zh.moegirl.org">zh.moegirl.org</a><br>
39 11 TxHeader c Content-Length: 14977<br> 40 11 TxHeader c Accept-Ranges: bytes<br> 41 11 TxHeader c Date: Wed, 14 May 2014 15:52:33 GMT<br> 42 11 TxHeader c X-Varnish: 1750481507 1750481502<br>
43 11 TxHeader c Age: 180<br> 44 11 TxHeader c Via: 1.1 varnish<br> 45 11 TxHeader c Connection: keep-alive<br> 46 11 TxHeader c v-Cache: HIT<br> 47 11 Length c 14977<br> 48 11 ReqEnd c 1750481507 1400082753.326334476 1400082753.326504469 0.000313997 0.000061512 0.000108480<br>
<br><br><br><b>Varnish Log From Client 2 (192.168.66.106)</b><br><br> 1 11 SessionOpen c 192.168.66.106 34154 :80<br> 2 11 ReqStart c 192.168.66.106 34154 1750481508<br> 3 11 RxRequest c GET<br> 4 11 RxURL c /Mainpage<br>
5 11 RxProtocol c HTTP/1.1<br> 6 11 RxHeader c Host: <a href="http://zh.moegirl.org">zh.moegirl.org</a><br> 7 11 RxHeader c Connection: keep-alive<br> 8 11 RxHeader c Cache-Control: max-age=0<br>
9 11 RxHeader c Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8<br> 10 11 RxHeader c User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.132 Safari/537.36<br>
11 11 RxHeader c Accept-Encoding: gzip,deflate,sdch<br> 12 11 RxHeader c Accept-Language: zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4,en-US;q=0.2,en-GB;q=0.2<br> 13 11 RxHeader c Cookie: __gads=ID=b048dccb69e9da93:T=1399163153:S=ALNI_Mao_IUR1acm9tlz_9E4C5DuSDZ98g; wikiEditor-0-booklet-characters-page=latin; wikiEditor-0-toolbar- section=advanced; moegirlSSOUserName=Fishthirteen; moegirlSSO_session=bfmb7k0dadsau1dalp5ou53uc6; moegir<br>
14 11 VCL_call c recv lookup<br> 15 11 VCL_call c hash<br> 16 11 Hash c /Mainpage<br> 17 11 Hash c <a href="http://zh.moegirl.org">zh.moegirl.org</a><br> 18 11 VCL_return c hash<br>
19 11 Hit c 1750481474<br> 20 11 VCL_call c hit deliver<br> 21 11 VCL_call c deliver deliver<br> 22 11 TxProtocol c HTTP/1.1<br> 23 11 TxStatus c 200<br> 24 11 TxResponse c OK<br>
25 11 TxHeader c Server: nginx/1.6.0<br> 26 11 TxHeader c Content-Type: text/html; charset=UTF-8<br> 27 11 TxHeader c Vary: Accept-Encoding, Accept-Encoding, Cookie, Accept-Language<br> 28 11 TxHeader c X-Content-Type-Options: nosniff<br>
29 11 TxHeader c Content-language: zh<br> 30 11 TxHeader c Cache-Control: s-maxage=2678400, must-revalidate, max-age=0<br> 31 11 TxHeader c Last-Modified: Mon, 12 May 2014 20:01:11 GMT<br> 32 11 TxHeader c Content-Encoding: gzip<br>
33 11 TxHeader c X-Varnish: 1594676989<br> 34 11 TxHeader c Via: 1.1 varnish<br> 35 11 TxHeader c X-Cache: MISS<br> 36 11 TxHeader c host: <a href="http://zh.moegirl.org">zh.moegirl.org</a><br>
37 11 TxHeader c Content-Length: 14975<br> 38 11 TxHeader c Accept-Ranges: bytes<br> 39 11 TxHeader c Date: Wed, 14 May 2014 15:53:18 GMT<br> 40 11 TxHeader c X-Varnish: 1750481508 1750481474<br>
41 11 TxHeader c Age: 514<br> 42 11 TxHeader c Via: 1.1 varnish<br> 43 11 TxHeader c Connection: keep-alive<br> 44 11 TxHeader c v-Cache: HIT<br> 45 11 Length c 14975<br> 46 11 ReqEnd c 1750481508 1400082798.821015596 1400082798.821227551 0.000247717 0.000054121 0.000157833<br>
<br><br><b>You can see the hash keys are same (</b><b>/Mainpage + </b><b><a href="http://zh.moegirl.org">zh.moegirl.org</a>) but the hit object is different(1750481502 and 1750481474)</b><br><br><br><b>And following is my default.vcl</b>. I just change a little from the default vcl settings.<br>
<br><span style="font-family:arial,helvetica,sans-serif">backend default {<br> .host = "<a href="http://zh.moegirl.org">zh.moegirl.org</a>";<br> .port = "80";<br>}<br># <br># Below is a commented-out copy of the default VCL logic. If you<br>
# redefine any of these subroutines, the built-in logic will be<br># appended to your code.<br> sub vcl_recv {<br> if (req.restarts == 0) {<br> if (req.http.x-forwarded-for) {<br> set req.http.X-Forwarded-For =<br>
req.http.X-Forwarded-For + ", " + client.ip;<br> } else {<br> set req.http.X-Forwarded-For = client.ip;<br> }<br><br><br> }<br> if (req.request != "GET" &&<br> req.request != "HEAD" &&<br>
req.request != "PUT" &&<br> req.request != "POST" &&<br> req.request != "TRACE" &&<br> req.request != "OPTIONS" &&<br> req.request != "DELETE") {<br>
/* Non-RFC2616 or CONNECT which is weird. */<br> return (pipe);<br> }<br> if (req.request != "GET" && req.request != "HEAD") {<br> /* We only deal with GET and HEAD by default */<br>
return (pass);<br> }<br><br>// if (req.http.Authorization || req.http.Cookie) {<br>// /* Not cacheable by default */<br>// //return (pass);<br>// }<br><br> if (req.http.Cookie ~ "UserID") {<br>
} else {<br> unset req.http.Cookie;<br> }<br><br><br> return (lookup);<br> }<br> <br> sub vcl_pipe {<br> # Note that only the first request to the backend will have<br> # X-Forwarded-For set. If you use X-Forwarded-For and want to<br>
# have it set for all requests, make sure to have:<br> # set bereq.http.connection = "close";<br> # here. It is not set by default as it might break some broken web<br> # applications, like IIS with NTLM authentication.<br>
return (pipe);<br> }<br> <br> sub vcl_pass {<br> return (pass);<br> }<br> <br> sub vcl_hash {<br> hash_data(req.url);<br> if (req.http.host) {<br> hash_data(req.http.host);<br> } else {<br> hash_data(server.ip);<br>
}<br><br> return (hash);<br> }<br> <br> sub vcl_hit {<br> return (deliver);<br> }<br> <br> sub vcl_miss {<br> return (fetch);<br> }<br> <br> sub vcl_fetch {<br><br> if (beresp.http.host != req.http.host) {<br>
set beresp.http.host = req.http.host;<br> }<br><br><br> //set beresp.http.host = "<a href="http://zh.moegirl.org:6081">zh.moegirl.org:6081</a>";<br><br><br> if (beresp.ttl <= 0s ||<br> beresp.http.Set-Cookie ||<br>
beresp.http.Vary == "*") {<br> /*<br> * Mark as "Hit-For-Pass" for the next 2 minutes<br> */<br> set beresp.ttl = 120 s;<br> return (hit_for_pass);<br>
}<br> return (deliver);<br> }<br> <br> sub vcl_deliver {<br> if (obj.hits > 0) {<br> set resp.http.v-Cache = "HIT";<br> } else {<br> set resp.http.v_Cache = "MISS";<br> }<br><br>
return (deliver);<br> }<br> <br> sub vcl_error {<br> set obj.http.Content-Type = "text/html; charset=utf-8";<br> set obj.http.Retry-After = "5";<br> synthetic {"<br> <?xml version="1.0" encoding="utf-8"?><br>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"<br> "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</a>"><br> <html><br>
<head><br> <title>"} + obj.status + " " + obj.response + {"</title><br> </head><br> <body><br> <h1>Error "} + obj.status + " " + obj.response + {"</h1><br>
<p>"} + obj.response + {"</p><br> <h3>Guru Meditation:</h3><br> <p>XID: "} + req.xid + {"</p><br> <hr><br> <p>Varnish cache server</p><br>
</body><br> </html><br> "};<br> return (deliver);<br> }<br> <br> sub vcl_init {<br> return (ok);<br> }<br> <br> sub vcl_fini {<br> return (ok);<br> }</span><br><br><br><b>And my enviroment</b><br>
<br>Varnish Version: 3.0.5<br>OS: Ubuntu 14.04 LTS<br></div>Browers: Chromium 34 (One is in Linux(Debain Testing), and other is in Windows 8)<br><br>Besides, please forgive my pool English.<br><br>Thank you very much!<br>
<br>Fish Thirteen<br></div>