Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm trying to configure varnish (following by: default_varnish3.vcl_.txt)

[alexus@wcmisdlin02 ~]$ rpm -q varnish
varnish-3.0.3-1.el5.centos.x86_64
[alexus@wcmisdlin02 ~]$ 

I'm making a very first hit through my browser (page loads fine), then I do it again through curl on my local machine:

[alexus@wcmisdlin02 ~]$ curl -I alexustest:6081
HTTP/1.1 200 OK
Server: Apache/2.2.15 (Red Hat)
X-Powered-By: PHP/5.3.3
Cache-Control: public, max-age=1800
Last-Modified: Thu, 11 Apr 2013 19:27:15 +0000
Expires: Sun, 11 Mar 1984 12:00:00 GMT
Vary: Cookie,Accept-Encoding
Content-Type: text/html; charset=utf-8
Date: Thu, 11 Apr 2013 19:27:16 GMT
X-Varnish: 1355259954
Age: 0
Via: 1.1 varnish
Connection: keep-alive
X-Served-By: wcmisdlin02.uftmasterad.org
X-Cache: MISS

it shows me X-Cache: MISS, when it really should have been a HIT (since this is second hit), so I do it again (3rd time and again from my Linux workstation).

[alexus@wcmisdlin02 ~]$ curl -I alexustest:6081
HTTP/1.1 200 OK
Server: Apache/2.2.15 (Red Hat)
X-Powered-By: PHP/5.3.3
Cache-Control: public, max-age=1800
Last-Modified: Thu, 11 Apr 2013 19:27:15 +0000
Expires: Sun, 11 Mar 1984 12:00:00 GMT
Vary: Cookie,Accept-Encoding
Content-Type: text/html; charset=utf-8
Date: Thu, 11 Apr 2013 19:27:19 GMT
X-Varnish: 1355259955 1355259954
Age: 3
Via: 1.1 varnish
Connection: keep-alive
X-Served-By: wcmisdlin02.uftmasterad.org
X-Cache: HIT
X-Cache-Hits: 1

[alexus@wcmisdlin02 ~]$ 

and now it's a HIT, it sounds like it's caching per client or something. As I said I'm using default_varnish3.vcl_.txt, so you can see my configuration as that, I only changed backend information to match my environment and also added following code (to produce HIT/MISS):

[root@wcmisdlin02 varnish]# cat vcl_deliver/resp.vcl 
set resp.http.X-Served-By = server.hostname;
if (obj.hits > 0) {
    set resp.http.X-Cache = "HIT";  
    set resp.http.X-Cache-Hits = obj.hits;
} else {
    set resp.http.X-Cache = "MISS"; 
}
[root@wcmisdlin02 varnish]# 

* UPDATE *

varnishncsa's:

10.52.208.221 - - [11/Apr/2013:15:45:35 -0400] "HEAD http://alexustest:6081/ HTTP/1.1" 200 0 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2"
10.100.0.35 - - [11/Apr/2013:15:45:38 -0400] "HEAD http://alexustest:6081/ HTTP/1.1" 200 0 "-" "curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5"
share|improve this question
    
Can you post some logfiles from varnish. Firstly the NCSA log details, and also the Varnish transactional log.. –  Tom O'Connor Apr 11 '13 at 19:42
    
please see my update: this is me through to do it via curl from two different place, and actually on second time I got HIT as well (so that worked fine), I also noticed that whenever I'm doing it from browser it does GET instead of HEAD, does it make difference in terms of caching or not? –  alexus Apr 11 '13 at 19:48
    
It shouldn't. I suspect a GET is more likely to be cached, as it's actually retrieving more than just the headers.. I'm not convinced you can warm the cache suitably by just HEADing paths. –  Tom O'Connor Apr 11 '13 at 19:52

1 Answer 1

first hit through my browser (page loads fine), then I do it again through curl

But you told the webcache you were going to serve different results based on the cookies and the content encoding:

Vary: Cookie,Accept-Encoding

Did you delete all the cookies in your browser before before the first request? Also how did you make the request from the browser - a reload has very different behaviour from a refresh.

(BTW if you're going to vary your by cookie and you're using sessions then you should make your cache controlprovate - otherwise you're making Varnish work hard for no benefit, indeed you could actually slow your site down).

share|improve this answer
    
would you mind explain a little bit more? goal is simple: let varnish serve content as much as possible without reaching out to backend server. –  alexus Apr 16 '13 at 16:58
    
Then don't add a 'vary' header. –  symcbean Apr 16 '13 at 18:11
    
Where do I add 'vary'? I've search my entire config I don't see 'vary' anywhere... –  alexus Apr 16 '13 at 19:01
    
On the webserver / application tier –  symcbean Apr 17 '13 at 8:24
    
I have "Header unset ETag" on my backend (apache) server, but maybe this isn't same thing that you're referring. I read it from Drupal's varnish module instruction somewhere.. –  alexus Apr 17 '13 at 15:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.