Varnish 4 : Remote Cache

血红的双手。 提交于 2020-01-17 05:53:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!