Is Varnish 4 able to follow a redirect and cache the destination?

Star Dot stardothosting at gmail.com
Fri Dec 2 14:36:04 CET 2016


On Fri, Dec 2, 2016 at 3:51 AM, Andreas Plesner <apj at mutt.dk> wrote:

>
> Yes. This is what we do:
>
> sub vcl_deliver {
>   if ((resp.status == 301) || (resp.status == 302)) {
>     set req.url = regsub(resp.http.Location,"^http://[^/]+(.*)","\1");
>     return(restart);
>   }
> }
>
> Handling of the host header (and all the possible backends) is left as an
> exercise for the reader.
>
> What this does is that it caches the redirect as well as the destination,
> thus
> sort-of normalizing the request, while still caching the ultimate
> destination
> only once.
>
>

Tentatively your rules work for me. Is there any way for varnish to cache
the 302 redirect if its on a completely different host? In my example we
are hitting media.domain.com which hits an nginx server that redirects it
to a completely different URL (S3) that varnish is not caching. After
testing your rule, I see that its definitely skipping a step and providing
the destination URL (S3) to the browser. But that destination is not being
cached.

Is there a way to hide that hostname/url change completely so its
transparent to the end user?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20161202/f6f13a53/attachment.html>


More information about the varnish-misc mailing list