0

I'm trying to figure out how to force WWW in varnish for only one domain. I saw this answer to remove WWW but I don't know how to translate it to force it.

Edit: To clarify, my nginx config was working fine. It was only after I added Varnish that this started happening. I found the culprit and answered my own question.

2

Don't use "if" without special needs. If is evil! The right way is ...

server {
    server_name somedomain.com;
    return 301 http://www.somedomain.com$request_uri;
}

server {
    server_name www.somedomain.com;

    # typical lines
    # ...
}
0

The following snippet is for the Nginx config:

if ($host !~* ^www\.) {
   rewrite ^(.*)$ http://www.$host$1 permanent;
}
0

I needed to remove this from my vcl file in Varnish.

if (req.http.host ~ "^(www\.)?domain\.com$") {
    set req.http.host = "www.domain.com"
    return (lookup);

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.