Edit /etc/varnish/default.vcl

sub vcl_recv {
  if (req.http.host ~ "^example.com") {
    return (synth (750, ""));
  }
}
sub vcl_synth {
  if (resp.status == 750) {
    set resp.status = 301;
    set resp.http.Location = "http://www.example.com" + req.url;
    return(deliver);
  }
}