Search code examples
varnishvarnish-vclvarnish-4varnish-3

Varnish cache only homepage first


I am new to varnish cache.i have a website xyz.com and i want cache homepage first only so how to start with varnish and how will the vcl file look like for homepage cache only.

Please help.


Solution

  • Here's some basic VCL code that will cache the homepage explicitly and rely on the built-in VCL behavior for all other requests.

    vcl 4.1;
    
    backend default {
        .host = "127.0.0.1";
        .port = "8080";
    }
    
    sub vcl_recv {
        if((req.method == "GET" || req.method == "HEAD") && req.url == "/") {
            return(hash);
        }
    }