server.ip for "undoing" namevirtualhosts issues

Chris Hecker checker at d6.com
Mon Jul 12 08:02:15 CEST 2010


I'm running the configuration #1 I mentioned here:

http://lists.varnish-cache.org/pipermail/varnish-misc/2010-June/004342.html

Basically, varnishd listening on a bunch of ips, and then httpd 
listening on localhost:80 and all the sites as NameVirtualHosts.  This 
seems to work well so far, but it has the disadvantage that if somebody 
goes to the raw ip addresses with their browser, they'll get the same site.

Can I use server.ip in vcl_recv to force the host to the right site if 
there's no host record?  What would the code look like to do this? 
Something like:

if(!req.http.host) {
	if(server.ip == "a.b.c.d") {
		set req.http.host = "a.com";
	} elsif(server.ip == "a.b.c.e") {
...etc

Would that work?  Has anybody tried that?

Thanks,
Chris





More information about the varnish-misc mailing list