Nginx – Ignore certain URLs on Varnish Cache

cachenginxvarnish

I'd like that Varnish completely ignored certain URLs on my websites.

I.e., www.site1.com/fileuploader and www.site2.com/fileuploader

I have 4 websites on the same VCL, and all those websites are using the same URL structure so the only thing that changes is the domain itself, the URLs I want Varnish to ignore are the same.

I've tried:

sub vcl_recv {
    if (req.url ~ "^/fileuploader/\?"
        )  {
        return(pipe);
    }
}

But it doesn't work. When trying to download a PDF through it I'm presented with a Varnish 503 Unavailable error (the same error I have if I didn't change the config). If I go through nginx directly using its port, it downloads fine.

Here's the varnishlog for this incident:

   16 ObjHeader    - Server: nginx/1.2.7
   16 ObjHeader    - Date: Wed, 17 Apr 2013 11:03:40 GMT
   16 ObjHeader    - Content-Type: application/pdf
   16 ObjHeader    - Content-Length: 1078550
   16 ObjHeader    - X-Powered-By: PHP/5.3.23-1~dotdeb.0
   16 ObjHeader    - Expires: Thu, 19 Nov 1981 08:52:00 GMT
   16 ObjHeader    - Set-Cookie: frontend=74go8sgckma5qrobnqc36pcjd4; expires=Wed, 17-Apr-2013 12:03:40 GMT; path=/; domain=www.site1.com; httponly
   16 ObjHeader    - Pragma: public
   16 ObjHeader    - Cache-Control: must-revalidate, post-check=0, pre-check=0
   16 ObjHeader    - Content-Disposition: attachment; filename=File-1338990998.pdf
   16 ObjHeader    - Content-Encoding: gzip
   16 ObjHeader    - Vary: Accept-Encoding
   30 FetchError   - Resource temporarily unavailable
   16 FetchError   - straight insufficient bytes

Best Answer

If you want to pass it absolutely untouched by Varnish, then the best option is return(pipe);, which basically tells Varnish to act as a dumb TCP proxy for the duration of the connection.

But the fact that you got a 503 response seems to imply that something else is wrong - can you provide the output from varnishlog when a request for that resource is made, if pipe mode doesn't do the trick?

Related Topic