How to configure varnish when backend is on shared hosting

This one was almost impossible to google out, so adding this solution here.

First of all backend:

backend default {
    .host = "blog.grzegorzpawlik.com";
    .port = "80";
}

But if host is actually parked domain on shared hosting, varnish will use resolved ip instead of domain name and shared hosting server will not know which catalog to serve.

You will see some general page (most probably similar to when you point a new domain to shared hosting server but didn’t park domain there yet).

The solution is easy:

sub vcl_recv {
   set req.http.host = "blog.grzegorzpawlik.com";
}

Just make sure you’ve restarted varnish and then purged cache:

sudo varnishadm  'ban req.url ~ ".*"'

Ofcourse this is just a start. And one need more sophisticated vcl_recl to effectively cache wp site.

Share Button

Leave a Reply

Your email address will not be published. Required fields are marked *