Apache proxypass to varnish instance returns localhost

apache-2.2PROXYvarnish

I've got a third party hosted blog that I'm using varnish to cache. The rest of my site is hosted and served directly via apache, so I've d proxy pass…since the httpd proxypass points to the localhost:varnishport the browser shows localhost/blog:

 ProxyPass /blog http://localhost:6081/blog  
 ProxyPassReverse /blog http://localhost:6081/blog

I tried using the following line in sub_vcl to try and rewrite the req.http.Host back:

   set req.http.Host = regsub(req.http.Host, "localhost", "example\.com");

but I receive a 502 proxy error from apache (see below). should I be setting the header logic in another section of the VCL for what gets passed back to apache?

"The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /blog.

Reason: DNS lookup failure for: www.localhost"

Best Answer

Put Varnish in front of Apache and cache your blog selectively with host+url condition:

sub vcl_recv {

...
...

# detect blog
if (req.http.Host == "example.com" && req.url ~ "^/blog") {
#
#put your cache rules here
#
}
else {
# other parts should be untouched (on your wish)
return(pipe);
}

...
...
}