Varnish: cache only specific domain

前端 未结 3 1526
春和景丽
春和景丽 2021-01-31 21:20

I have been Googling aggressively, but without luck.

I\'m using Varnish with great results, but I would like to host multiple websites on a single server (Apache), witho

3条回答
  •  别跟我提以往
    2021-01-31 21:45

    (edited after comment) It's req.http.host, so in your vcl file (e.g. default.vcl) do:

    sub vcl_recv {
      # dont cache foo.com or bar.com - optional www
       if (req.http.host ~ "(www\.)?(foo|bar)\.com") {
         pass;
       }
      # cache foobar.com - optional www
       if (req.http.host ~ "(www\.)?foobar\.com") {
         lookup;
       }
    }
    

    And in varnish3-vcl:

    sub vcl_recv {
      # dont cache foo.com or bar.com - optional www
       if (req.http.host ~ "(www\.)?(foo|bar)\.com") {
         return(pass);
       }
      # cache foobar.com - optional www
       if (req.http.host ~ "(www\.)?foobar\.com") {
         return(lookup);
       }
    }
    

提交回复
热议问题