Mailing List Archive

Varnish multiple backend configuration?
Would this work as a simple load balancer configuration?

backend apache {
set backend.host = ""; set backend.port = "80";
}

backend nginx {
set backend.host = ""; set backend.port = "80";
}

sub vcl_recv {
if (req.request != "GET" && req.request != "HEAD") {
pipe;
} if (req.http.Expect) {
pipe;
} if (req.http.Authenticate || req.http.Cookie) {
pass;
} lookup;
}

sub vcl_pipe {
pipe;
}

sub vcl_pipe {
pipe;
}

sub vcl_pass {
pass;
}

sub vcl_hash {
hash;
}

sub vcl_hit {
if (!obj.cacheable) {
pass;
} deliver;
}

sub vcl_miss {
if (req.url ~ "/.(php|py)$") {
set req.backend = apache; fetch;
}
else (req.url ~ "/.(*)$") {
set req.backend = nginx; fetch;
}
}

sub vcl_fetch {
if (!obj.valid) {
error;
} if (!obj.cacheable) {
pass;
} if (resp.http.Set-Cookie) {
pass;
} insert;
}

sub vcl_timeout {
discard;
}
Varnish multiple backend configuration? [ In reply to ]
In message <001201c7a7fa$51ca1810$6600a8c0 at octane>, Nathan McSween writes:
>Would this work as a simple load balancer configuration?

I don't think so, you will risk multiple concurrent transactions
getting mixed up about which backend they connect to or using
cached backend connections going to different places.

--
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 multiple backend configuration? [ In reply to ]
Nathan McSween <nwmcsween at gmail.com> writes:
> Would this work as a simple load balancer configuration?

Yes, except

> backend apache {
> set backend.host = ""; set backend.port = "80";
> }
>
> backend nginx {
> set backend.host = ""; set backend.port = "80";
> }

I assume you removed the host names intentionally before posting

> sub vcl_miss {
> if (req.url ~ "/.(php|py)$") {
> set req.backend = apache;
> fetch;
> } else (req.url ~ "/.(*)$") {
> set req.backend = nginx;
> fetch;
> }
> }

"else" does not take a condition, did you mean "else if"? In any case,
the second condition is not necessary, and neither are the two "fetch"
statements. The following should do:

sub vcl_miss {
if (req.url ~ "/.(php|py)$") {
set req.backend = apache;
} else {
set req.backend = nginx;
}
}


DES
--
Dag-Erling Sm?rgrav
Senior Software Developer
Linpro AS - www.linpro.no