Mailing List Archive

Varnish as an HTTP accelator for multiple Zope instances on multiple machines
Hi list,

I'm trying to use varnish as an HTTP accelerator for a Zope virtual
hosting shop. HTTP requests are to be dispatched based on the
hostname to different Zope backends which reside on different machines.

Varnish runs on Debian testing and my setup doesn't work. The
vcl.conf is simple and looks correct. (The conciseness of vcl.conf
was the prime reason to ditch squid btw) This is vcl.conf:

backend default {
set backend.host = "127.0.0.1";
set backend.port = "7080";
}


backend thishost {
set backend.host = "127.0.0.1";
set backend.port = "7080";
}

backend thathost {
set backend.host = "192.168.100.199";
set backend.port = "9080";
}

sub vcl_recv {
if (req.request == "POST") {
pipe;
}

# force lookup even when cookies are present
if (req.request == "GET" && req.http.cookie) {
lookup;
}

if (req.http.host ~ "^hop.metatest.de") {
set req.backend = thishost;
} elsif (req.http.host ~ "^zop.metatest.de") {
set req.backend = thathost;
} else {
error 404 "Unknown virtual host";
}


}

sub vcl_fetch {
# force minimum ttl of 180 seconds
if (obj.ttl < 180s) {
set obj.ttl = 180s;
}
}

/etc/default/varnish hasn't been changed.

varnishlog gives me this output:

13 RxHeader c Connection: keep-alive
13 RxHeader c Host: zop.metatest.de
13 VCL_call c recv
13 VCL_return c lookup
13 VCL_call c miss
13 VCL_return c fetch
17 BackendClose default
17 BackendOpen b default 127.0.0.1 46677 127.0.0.1 7080

So varnish goes to 127.0.0.1 instead of 192.168.100.199.

Any pointers what is wrong?

Thanks a lot!

-- Dirk
Varnish as an HTTP accelator for multiple Zope instances on multiple machines [ In reply to ]
Dirk Gomez <lists at dirkgomez.de> writes:
> sub vcl_recv {
> if (req.request == "POST") {
> pipe;
> }
>
> # force lookup even when cookies are present
> if (req.request == "GET" && req.http.cookie) {
> lookup;
> }
>
> if (req.http.host ~ "^hop.metatest.de") {
> set req.backend = thishost;
> } elsif (req.http.host ~ "^zop.metatest.de") {
> set req.backend = thathost;
> } else {
> error 404 "Unknown virtual host";
> }
>
>
> }

You should select the backend *before* checking for POST or cookies.

> varnishlog gives me this output:
>
> 13 RxHeader c Connection: keep-alive
> 13 RxHeader c Host: zop.metatest.de
> 13 VCL_call c recv
> 13 VCL_return c lookup
> 13 VCL_call c miss
> 13 VCL_return c fetch
> 17 BackendClose default
> 17 BackendOpen b default 127.0.0.1 46677 127.0.0.1 7080
>
> So varnish goes to 127.0.0.1 instead of 192.168.100.199.

Most likely, the client sent a cookie.

DES
--
Dag-Erling Sm?rgrav
Senior Software Developer
Linpro AS - www.linpro.no
Varnish as an HTTP accelator for multiple Zope instances on multiple machines [ In reply to ]
In message <C2604441-3817-4975-817A-70AC5DB1C2B4 at dirkgomez.de>, Dirk Gomez writ
es:

>varnishlog gives me this output:
>
> 13 RxHeader c Connection: keep-alive
> 13 RxHeader c Host: zop.metatest.de
> 13 VCL_call c recv
> 13 VCL_return c lookup
> 13 VCL_call c miss
> 13 VCL_return c fetch
> 17 BackendClose default
> 17 BackendOpen b default 127.0.0.1 46677 127.0.0.1 7080
>
>So varnish goes to 127.0.0.1 instead of 192.168.100.199.
>
>Any pointers what is wrong?

In cases like this, set the parameter vcl_trace to true
and varnish will log where it goes in the VCL code by
line and character:

11 VCL_call c recv
11 VCL_trace c 1 1.22
n l.c

n = serial number of token (ignore this)
l = line number
c = character in line

11 VCL_trace c 2 2.9
11 VCL_trace c 5 5.5
11 VCL_trace c 6 5.9
11 VCL_trace c 8 8.5
11 VCL_trace c 9 8.9
11 VCL_trace c 10 8.34
11 VCL_trace c 12 11.5
11 VCL_return c lookup

In this case it was the default VCL:

1 sub default_vcl_recv {
....5...10...15...20.^ = 1.22
2 if (req.request != \"GET\" && req.request != \"HEAD\") {
....5...^ = 2.9
3 pipe;
4 }
5 if (req.http.Expect) {
....^ = 5.5
....5...^ = 5.9
6 pipe;
7 }
8 if (req.http.Authenticate || req.http.Cookie) {
....^ = 8.5
....5...^ = 8.9
....5...10...15...20...25...30...^ = 8.34
9 pass;
10 }
11 lookup;
....^ = 11.5
}


Remember to count TAB characters as one char only.

--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
Varnish as an HTTP accelator for multiple Zope instances on multiple machines [ In reply to ]
Dag, thanks a lot. That exactly solved my problem!

-- Dirk