4

Is there a way to define lists of domains in Varnish VCL language? I suppose something similar for ACLs. I would like to do something like this (using ACLs as an example).

acl website_list {
    '(www\.)?domain.tld';
    '(www\.)?domain2.tld';
}
...
if(req.http.Host ~ website_list) return(lookup);

I could just use separate RegEx tests but it isn't very re-usable if I want to use those domains somewhere else in the VCL.

Thanks!

Charles
  • 50,943
  • 13
  • 104
  • 142
rATRIJS
  • 309
  • 1
  • 5

1 Answers1

0

You could have a test condition which sets a marker header, then test for that later on:

sub vcl_recv {
  if (req.http.Host ~ "^(www\.)?domain.tld" || 
      req.http.Host ~ "^(www\.)?domain2.tld") {

    /* Set the magic marker */
    set beresp.http.magicmarker = "1";
  }

  if (resp.http.magicmarker) {
    return(lookup);
  }
}
uknzguy
  • 409
  • 3
  • 4
  • 1
    While this solves the specific example given, it's not an answer to the question "How can I define a list in VCL" – I, too, need a way to define a list to be matched against, and this solution doesn't solve my problem :T – Matheus Avellar Dec 10 '19 at 13:09