Proxy pass to varnish not hitting cache

apache-2.2http-proxyvarnish

On my web server I have a varnish instance that I would like to cache a third party hosted website (at blog.company.com/blog). I have a proxypass for this since the rest of the site is hosted locally and would like for the browser to masquerade this to it appears to be part of our website (company.com/blog)

(/etc/httpd/conf.d/proxy.conf)
ProxyTimeout 300

# Blog
ProxyPass /blog http://localhost:8000
ProxyPassReverse /blog http://localhost:8000

And I have the varnish backend pointed to the blog.sugarsync.com:

backend default {
  .host = "70.40.204.127";
  .port = "80";
}

The page resolves, but the page essentially gets redirected to blog.company.com/blog, and it doesn't ever hit the cache…varnishlog shows a "pass" function with it receives the GET request, meaning that it isn't which is strange because I'm using all default behaviors in /etc/varnish/default.vcl outside of the custom backend, so it shouldn't be passing them…

   11 SessionOpen  c 127.0.0.1 46485 0.0.0.0:8000
   11 ReqStart     c 127.0.0.1 46485 394102336
   11 RxRequest    c GET
   11 RxURL        c /
   11 RxProtocol   c HTTP/1.1
   11 RxHeader     c Host: localhost:8000
   11 RxHeader     c User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4
   11 RxHeader     c Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
   11 RxHeader     c Accept-Encoding: gzip,deflate,sdch
   11 RxHeader     c Accept-Language: en-US,en;q=0.8
   11 RxHeader     c Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
   11 RxHeader     c Cookie: __utmx=74837904.GQgj_x3FQCSgKU8YgJ937g$30088162-10:0; __utmxx=74837904.GQgj_x3FQCSgKU8YgJ937g$30088162-10:1351630608:15552000; __utmx=32887036.GQgj_x3FQCSgKU8YgJ937g$30088162-10:0; __utmxx=32887036.GQgj_x3FQCSgKU8YgJ937g$30088162-10:1351791703:155
   11 RxHeader     c scns-hdr-ip: 50.76.54.11
   11 RxHeader     c X-Forwarded-For: 10.5.112.22
   11 RxHeader     c X-Forwarded-Host: www.s.company.com
   11 RxHeader     c X-Forwarded-Server: www.company.com
   11 RxHeader     c Connection: Keep-Alive
   11 VCL_call     c recv
   11 VCL_return   c pass
   11 VCL_call     c pass
   11 VCL_return   c pass

What's strange is that when I type the hostname directly (hostname.company.com:8000 or company.com/blog), it hits the varnish cache properly, but still gets the url redirected in the browser. Curls to the correct url (www.company.com/blog) also hit the cache. Subdomains also do not appear to work…what's going on here?

Best Answer

The reason pass is occurring is because the default VCL logic refuses to cache anything with an Authorization or Cookie in the request headers, and your request has a Cookie.

if (req.http.Authorization || req.http.Cookie) {
    /* Not cacheable by default */
    return (pass);
}

That default behavior is out of an abundance of caution, so that servers where different content is returned for a page in response to the user's session; you can modify this behavior in your vcl_recv. Implement yours as a copy of the default, but strip out the req.http.Cookie check:

if (req.http.Authorization) {
    /* Not cacheable by default */
    return (pass);
}

In terms of the redirect behavior, sounds like it's getting a 30x response, which is redirecting the client browser - can you provide the logs for one of those hits?

Related Topic