Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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?

share|improve this answer
    
yes, the response is 302'd, so it's a permanent redirect. I didn't know that proxypass did that...here's a sample response: 10.5.112.22 - - [05/Nov/2012:11:45:05 -0800] "GET /blog HTTP/1.1" 302 229 "-" "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" –  580farm Nov 5 '12 at 20:46
    
there's also the following hits in my rewrite log: 10.5.112.22 - - [05/Nov/2012:11:45:10 --0800] [company.com/sid#2b14c49791d8][rid#2b14d2ff1130/initial] (2) init rewrite engine with requested uri /blog 10.5.112.22 - - [05/Nov/2012:11:45:10 --0800] [cp,[company.com/sid#2b14c49791d8][rid#2b14d2ff1130/initial] (1) pass through /blog –  580farm Nov 5 '12 at 20:50
    
@580farm ProxyPass does not do that, it translates redirects if they're present but does not generate them. The application is what's generating them; can you get them to send the correct Location response? If not, we might be able to mangle it in Varnish or Apache. –  Shane Madden Nov 5 '12 at 23:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.