Varnish and hot linking

Chris Ferry chris at futuredead.com
Thu Jul 3 00:19:31 CEST 2008


I've set up varnish to handle hot linking, but I have an issue with  
varnish caching the "hotlink" image for the image request.

Here's the relevant part of default.vcl:

sub vcl_recv {

# Add a unique header containing the client address
remove req.http.X-Forwarded-For;
set    req.http.X-Forwarded-For = client.ip;
         if (req.request == "GET") {
                 if ( !(req.http.referer ~ "[a-z0-9]+.domain.com| 
yahoo.|rssbandit.org|newsgator.com|google.|search?q=cache" ) &&  
(req.http.host ~ "^(raw)?images.domain.") && (req.http.referer) ) {
                     set req.url="http://images.domain.com/hotlink.gif";
                     pass;
                 }
                 lookup;
         }

         if (req.request == "PURGE") {
                 purge_url(req.url);
                 error 200 "OK!!";
         }
}

The problem is this,  a user hotlinks http://images.domain.com/puppy.jpeg 
  and we return hotlink.gif.
Now if a user legitimately loads puppy.jpeg he receives the cached  
copy of hotlink.gif in its place.
I though by setting the req.url that the cached file is now  
hotlink.gif and we haven't even attempted to store puppy.jpeg in the  
cache.
I need to legitimately serve puppy.jpeg even if it's being hotlinked  
from somewhere.
Any help would be appreciated.
Thanks
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20080702/f9c47ba1/attachment-0001.html>


More information about the varnish-misc mailing list