问题
Good day. I need some help, I cant get any HIT/MISS response in varnish. please help me.. thanks in advance.. Here is my default.vcl configuration.
backend default {
.host = "00.00.00.00";
.port = "80";
}
sub vcl_recv {
if (req.http.host == "www.example.com") {
unset req.http.cookie;
unset req.http.Vary;
}
else
{
return (pass);
}
}
sub vcl_backend_response {
set beresp.do_gzip = true;
unset beresp.http.Cache-Control;
set beresp.ttl = 1h;
set beresp.grace = 1w;
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
回答1:
The only backend you declare is 0.0.0.0
, you should declare a correct backend ip or dns.
Varnish is a reverse proxy, it won't follow the Header:Host => IP http way. It needs to be explicitly declare where to forward the request.
回答2:
Your backend port is pointing to where Varnish should be listening. Varnish should be listening on 80, and the backend default should be the port Apache is now listing on. In your VCL change it to:
backend default {
.host = "127.0.0.1";
.port = "82";
}
Your /etc/varnish/varnish.params file should have the port set to 80
VARNISH_LISTEN_PORT=80
and in your http.conf, you should set Apache to listen on 82.
Listen 0.0.0.0:82
Restart Apache, then Varnish. Now you'll properly proxy traffic back to Apache. The IPs I gave are examples, YMMV.
Proper flow:
[Internet] <-> (80)[Varnish] <-> (82)[Apache].
来源:https://stackoverflow.com/questions/40100313/varnish-4-remote-cache