1

I would like to configure my varnish server to have different .vcl configurations according to the hostname. I have wordpress and magento in the same server apache+varnish 4.1.2

This is the default.vcl I tried to create, but I need to include a specific vcl for wordpress?

vcl 4.0;

# Default backend definition. Set this to point to your content server.
backend default {
    .host = "127.0.0.1";
    .port = "8888";
}

sub vcl_recv {
    # Happens before we check if we have this in cache already.
    #
    # Typically you clean up the request here, removing cookies you don't need,
    # rewriting the request, etc.
if (! req.http.Host) { error 404 "Need a host header"; }
 set req.http.Host = regsub(req.http.Host, "^www\.", "");
 set req.http.Host = regsub(req.http.Host, ":80$", "");
if (req.http.Host == "hostname1.com") {  include "/etc/varnish/wordpress.vcl"; }
elsif (req.http.Host == "hostname2.com") {include "/etc/varnish/magento.vcl";}
}

sub vcl_backend_response {
}

sub vcl_deliver {

}
5
  • That should work? You've just got to be aware, the include will act just in the sub_recv section, not anywhere else. There's some examples with includes/vhosts here: info.varnish-software.com/blog/virtual-hosts-varnish
    – Kirrus
    Apr 22, 2016 at 18:25
  • ok but what should I put in my wordpress.vcl? Apr 28, 2016 at 8:58
  • The vcl to ensure WordPress is cached? There are plenty of guides available if you google them.
    – Kirrus
    Apr 28, 2016 at 16:35
  • yes ok, but do I have to repeat the same vcl sintax as my default.vcl? because I have tried already and I get errors Apr 29, 2016 at 14:51
  • No, you need only the syntax for the WordPress site. Assume the code in WordPress.vcl is injected where you include it, and is executed there in the flow
    – Kirrus
    Apr 30, 2016 at 23:45

0

You must log in to answer this question.

Browse other questions tagged .