Search code examples
ubuntuvarnish-vcl

Varnish Cache: Specific Domain only NOT ALL


I need help. Is possible to cache a specific domain only, since I want not all domain to be cache, I want example.com only. Can I ask for configuration for it.. thanks in advance. I am using Varnish Cache 4.

I only have this

/etc/varnish/default.vcl

 backend marketics {
   .host = "127.0.0.1";
   .port = "7080";
 }

where my apache port is 7080 .


Solution

  • You need to return pass for the other domains :

    sub vcl_recv {
      if (! req.host == "example.com") {
        return (pass);
      }
      #else failover to the default behaviour
    }
    

    pass tells Varnish not to look into its cache, it will always fetch the content from the backend.