Reputation: 11
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?
Thanks.
Upvotes: 1
Views: 1291
Reputation: 5559
By step 4;
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)
do you mean that it results in a HTTP Redirect? Then you could check the backend response status code in vcl_fetch (check for 301, 302 etc), use the Location header as your new url and do a restart. I found a great example of this in the Varnish Book
sub vcl_fetch {
if (req.restarts == 0 &&
req.request == "GET" &&
beresp.status == 301) {
set beresp.http.location = regsub(beresp.http.location,"^http://","");
set req.http.host = regsub(beresp.http.location,"/.*$","");
set req.url = regsub(beresp.http.location,"[^/]*","");
return (restart);
}
}
Upvotes: 2