Serving Backends

Michael Alger varnish at mm.quex.org
Fri Oct 1 16:36:46 CEST 2010


On Fri, Oct 01, 2010 at 02:22:37PM +0000, Davies Matt J A (LCSS) wrote:
> 
> I've defined a backend that is my application server,
> 
> backend a {
>   .host = "application_server_fqdn";
>   .port = "80";
> }
> 
> and then defined some further code to serve that backend from my
> varnish server
> 
> sub vcl_recv {
> 
> if (req.http.host == "www.a.com") {
>         set req.backend = a;
>     }
> 
> }
> 
> What I'm finding is that if I make up anything in my /etc/hosts
> file to point at the varnish servers IP address, it will serve the
> site.  Even the IP address of the varnish server serves the
> application.
> 
> I don't want that to happen.

Varnish will use the first backend defined as the default, i.e.
req.backend is always set to something even if you don't set it
yourself. Not sure if it's actually just the first backend defined
or some other criteria; but the point is there's always a backend
for it to use even if you don't specify it explicitly.

If you really want to only serve if the hostname in the request
header is recognised, you'll have to tell Varnish to display an
error, or change the request so it will go to a backend that
displays an error page, or something similar.

i.e.

if (req.http.host == "www.a.com") {
  set req.backend = a;
}
else {
  error 404 "Not found";
}




More information about the varnish-misc mailing list