Hiding internal backend requests

Darvin Denmian darvin.denmian at gmail.com
Mon Jun 18 22:41:37 CEST 2012


That's great!

Thanks for your reply, I'll try it.

On Mon, Jun 18, 2012 at 5:26 PM, Hugo Cisneiros (Eitch)
<hugo.cisneiros at gmail.com> wrote:
> On Wed, Jun 13, 2012 at 7:26 PM, Darvin  Denmian
> <darvin.denmian at gmail.com> wrote:
>> That is my scenario:
>>
>> 1) Varnish (172.16.217.131:80), receives a request from a client, i.e:
>> http://172.16.217.131:80/a.png
>> 2) Request is forwarded to the Default Backend (127.0.0.1:8000)
>> 3) Default backend receive the request and process it
>> 4) That processing results in a new URL, i.e:
>> http://172.16.217.132:80/a.png (**As you can see the IP has changed)
>> 5) 172.16.217.132:80 is another backend in Varnish's config file
>> 6) The new URL points to a resource that should be provided by Varnish
>> (that resource generally is an image)
>>
>> My problem is: The client needs to execute 2 GETs to obtain the image.
>>
>> My question:  How can I configure varnish to internally receive the
>> response from the first backend(127.0.0.1:8000), and fetch data from
>> the second backend (172.16.217.132:80), and after that, send the data
>> to the client?
>
> It's not simple, but it's possible. I use this approach with much success here.
>
> You will need something in the first backend response to differentiate
> the internal redirect from the successful request. For example, if the
> first backend needs to check another backend, you must write a HTTP
> header ("req.http.X-Internal-Redirect = True", for example).
>
> Then, on vcl_fetch, you use something like this:
>
> if (beresp.http.X-Internal-Redirect == "True") {
>   set req.http.X-Internal-Redirect = "True");
>   return (restart);
> }
>
> With "return (restart)", your request will be restarted from scratch
> (entering vcl_recv), but with the additional header. Now you can set
> your other backend on vcl_recv based on this new header, like this on
> vcl_recv:
>
> if (req.http.X-Internal-Redirect == "True") {
>   set req.backend = another_backend;
> }
>
> This new backend can't reply the additional header since this could
> create a restart loop.
>
> Good luck! :)
>
> --
> []'s
> Hugo
> www.devin.com.br
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc



More information about the varnish-misc mailing list