I am new at working with varnish. I installed it, I think i configured it correctly. In order to test this is what i did:
I created a test page that only has the string "test".
I went to the page and it has these headers:
Accept-Ranges:bytes
Age:0
Cache-Control:max-age=120
Connection:keep-alive
Content-Length:6
Content-Type:text/html; charset=UTF-8
Date:Tue, 12 May 2015 19:35:34 GMT
Expires:Tue, 12 May 2015 19:37:34 GMT
Server:Apache/2.2.15 (CentOS)
Via:1.1 varnish-v4
X-Powered-By:PHP/5.3.3
X-Varnish:32829
I change the text in the file to "test2"
I go to the page and it shows "test2". I believe it should be showing "test" if it was caching correctly.
I don't have cookies set up or anything, just that. My vcl is very simple:
vcl 4.0;
# Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you don't need,
# rewriting the request, etc.
}
sub vcl_backend_response {
# Happens after we have read the response headers from the backend.
#
# Here you clean the response headers, removing silly Set-Cookie headers
# and other mistakes your backend does.
#This will set up "grace mode".
set beresp.ttl = 10s;
set beresp.grace = 1h;
}
sub vcl_deliver {
# Happens when we have all the pieces we need, and are about to send the
# response to the client.
#
# You can do accounting or modifying the final object here.
}
Any idea? Thanks
Best Answer
Chances are good that are sending cookies in your request. Varnish doesn't cache anything with cookies in them. This from the builtin.vcl for Varnish 4:
You need to remove unwanted cookies in your VCL, as shown in this example from the Varnish website
If you test with
curl -i URL
, you won't send any cookies, and you if you repeat that more than a second later, you should get an Age header greater than 0.