Question

I have setup varnish on a server that runs two sites on two different domains, varnish works perfect without www in front of the two domains, I have attached the vcl file in this pastebin, I guess it's a basic misconfiguration somewhere, but I can't figure out where - does anyone know of a solution?

http://pastebin.com/CF37isis

Was it helpful?

Solution

To me the configuration looks fine and you should not get any troubles with/without www. Are you sure the DNS is pointing to your varnish server for the www? Of course there's also the possibility that your application acts differently and sets extra cookies/headers on the www request.

Further you should really redirect one of the www/non-www to the other so that only one is always used but both works (can also easily be done with varnish, or also probably in your DNS providers settings).

A redirect in varnish could look something like this (do not this needs to be added in your current vcl_recv/vlc_error and you should not add new blocks):

sub vcl_recv {
    if (req.http.host == "www.somedomain.com") {
        set req.http.x-Redir-Url = "http://somedomain.com" + req.url;
        error 750 req.http.x-Redir-Url;
    }
    if (req.http.host == "www.someotherdomain.com") {
        set req.http.x-Redir-Url = "http://someotherdomain.com" + req.url;
        error 750 req.http.x-Redir-Url;
    }
}

sub vcl_error {
    if (obj.status == 750) {
        set obj.http.Location = obj.response;
        set obj.status = 301;
        return (deliver);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top