Making varnish cache only certain requests with multiple backends

Dridi Boukelmoune dridi at varni.sh
Thu May 19 13:11:08 CEST 2016


On Thu, May 19, 2016 at 10:16 AM, Debraj Manna <subharaj.manna at gmail.com> wrote:
> Hi,
>
> We are using varnish for multiple round robin backends. as shown below:-
>
> backend d1 {
>     .host = "172.16.84.69";
>     .port = "9802";
> }
> backend d2 {
>     .host = "172.16.84.68";
>     .port = "9802";
> }
> backend r1 {
>     .host = "172.16.84.69";
>     .port = "9802";
> }
> backend r2 {
>     .host = "172.16.84.68";
>     .port = "9802";
> }

You don't need to duplicate backend definitions, your directors d and
r can share two backends b1 and b2.
> Can some one please let me know  if the below code is the best way to
> achieve what I am trying to do?
> if(req.http.Type == "p") {
>       req.backend_hint = r.backend();
>        return (pipe);
>    }

It looks OK but if your client sends subsequent HTTP requests, Varnish
won't see them after a return(pipe). You may use return(pass) instead,
to bypass Varnish for individual requests.

Dridi



More information about the varnish-misc mailing list