<div dir="ltr">Hi All,<div><br></div><div>I'm looking for information on what is by all indications an unusual setup.</div><div><br></div><div>We are attempting to proxy and cache from a single domain (e.g., <a href="http://test.example.com" target="_blank">test.example.com</a>) to individual pages on many backend domains (e.g., <a href="http://test.domainone.com/page" target="_blank">test.domainone.com/page</a>, <a href="http://test.domaintwo.com/anotherpage" target="_blank">test.domaintwo.com/anotherpage</a><wbr>, etc.).</div><div><br></div><div>The goal is to be able to hit a path on <a href="http://test.example.com" target="_blank">test.example.com</a> and have it returned the cached page for a backend domain/path.  For example:</div><div><br></div><div><a href="http://test.example.com/apple" target="_blank">test.example.com/apple</a>/ -> <a href="http://test.domainone.com/pear" target="_blank">test.domainone.com/pear</a>/</div><div><a href="http://test.example.com/peach" target="_blank">test.example.com/peach</a>/ -> <a href="http://test.domaintwo.com/strawberry" target="_blank">test.domaintwo.com/strawberry</a>/</div><div>... and so on.</div><div><br></div><div>The backend pages can be anything (HTML, Wordpress, Joomla, etc.), and are almost always a "sub-page" of the site rather than the index.  We have no control over the backend servers, so we can't alter their site's code directly.</div><div><br></div><div>We've so far been able to get the general proxy working.  The problem is that for any linked resources that are a level above the backend pages they either miss the cache (for absolute links) or hit a bad gateway because they don't match one of the cached paths.  For example:</div><div><br></div><div>For: <a href="http://test.example.com/apple" target="_blank">test.example.com/apple</a>/ -> <a href="http://test.domainone.com/pear" target="_blank">test.domainone.com/pear</a>/</div><div><br></div><div>(linked) <a href="http://test.domainone.com/wp-content/css/style.css" target="_blank">test.domainone.com/wp-content/<wbr>css/style.css</a> -> <a href="http://test.example.com/wp-content/css/style.css" target="_blank">test.example.com/wp-content/<wbr>css/style.css</a> (returns bad gateway because <a href="http://test.example.com/wp-content" target="_blank">test.example.com/wp-content</a>/ doesn't exist)</div><div>OR</div><div>(linked) <a href="http://test.domainone.com/wp-content/css/style.css" target="_blank">test.domainone.com/wp-content/<wbr>css/style.css</a> -> (rewrite) <a href="http://test.example.com/apple/wp-content/css/style.css" target="_blank">test.example.com/apple/wp-<wbr>content/css/style.css</a> -> <a href="http://test.domainone.com/pear/wp-content/css/style.css" target="_blank">test.domainone.com/pear/wp-<wbr>content/css/style.css</a> (404 because it doesn't exist).</div><div><br></div><div>So far we've attempted to solve this by using "sticky sessions" to set a cookie, and then direct traffic to the correct backend if either the path matches or the cookie is set, but we haven't gotten it quite right yet.  We're also concerned that using a cookie for this may affect caching.</div><div><br></div><div>Example config:</div><div><br></div><div><div>import cookie;</div><div>import header;</div><div><br></div><div>backend domain_one {</div><div>    .host = "<a href="http://test.domainone.com">test.domainone.com</a>";</div><div>    .port = "80";</div><div>}</div><div><br></div><div>backend domain_two {</div><div>    .host = "<a href="http://test.domaintwo.com">test.domaintwo.com</a>";</div><div>    .port = "80";</div><div>}</div><div><br></div><div>sub vcl_recv {</div><div>   if (req.http.host == "<a href="http://test.example.com">test.example.com</a>") {</div><div>      </div><div>      cookie.parse(req.http.cookie);</div><div>      if(cookie.get("sticky")) {</div><div>          set req.http.sticky = cookie.get("sticky");</div><div>      }</div><div><br></div><div>      if(req.http.sticky == "domain_one" || req.url ~ "^/apple/") {</div><div>         set req.http.sticky = "domain_one";</div><div><span style="white-space:pre">     </span> set req.http.host = "<a href="http://test.domainone.com">test.domainone.com</a>";</div><div>         set req.backend_hint = domain_one;</div><div><span style="white-space:pre">     </span> if(req.url == "/apple/") {</div><div><span style="white-space:pre">         </span> set req.url = "/pear/";</div><div>         }</div><div>      }</div><div>      if (req.http.sticky == "domain_two" || req.url ~ "^/peach/") {</div><div>         set req.http.sticky = "domain_two";</div><div><span style="white-space:pre"> </span> set req.http.host = "<a href="http://test.domaintwo.com">test.domaintwo.com</a>";</div><div>         set req.backend_hint = domain_two;</div><div><span style="white-space:pre">     </span> if(req.url == "/peach/") {</div><div><span style="white-space:pre">         </span> set req.url = "/strawberry/";</div><div>         }</div><div>      } </div><div>   }</div><div>}</div><div><br></div><div>sub vcl_deliver {</div><div>    if(req.http.sticky) {</div><div>        header.append(resp.http.Set-Cookie,"sticky=" + req.http.sticky + ";");</div><div>    }</div><div>}</div></div><div><br></div><div>With this configuration if I go to <a href="http://test.example.com/apple/">test.example.com/apple/</a> it will load the HTML for <a href="http://test.domainone.com/pear/">test.domainone.com/pear/</a>, and I do get 'Set-Cookie: sticky=domain_one;' in the initial response.  However, all the cookie isn't passed in subsequent linked requests, so I get 503 errors for all of the other static content and images (that should be served by <a href="http://test.domainone.com/wp-content/css/style.css,for">test.domainone.com/wp-content/css/style.css,for</a> example), resulting in a broken page.</div><div><br></div><div>This setup may not be possible, but as I don't have a lot of Varnish experience I'm trying to make sure I'm not missing something simple.</div><div><br></div><div><br></div><div><div><br></div>-- <br><div class="gmail-m_2799459411309058073gmail_signature"><div dir="ltr"><br><div>Thank You,</div><div><br></div><div>Logan B</div><div>NetActuate, Inc.</div></div></div>
</div></div>