virtual host remapping.

Chris Johnson johnson at nmr.mgh.harvard.edu
Mon Feb 14 15:42:29 CET 2011


      Hi,

      A quick restatement of the problem.  I have virtual hosts on my
server and I want to phase one out and move to another but don't
want varnish double caching both sites as they are of course the same.

      Following is the top chunk of default.vcl.  The only things I've
added are the freesurfer backend definition

backend freesurfer {
       .host = "127.0.0.1";
       .port = "8080";
}

and the second if

     if (req.http.host ~ "^sufer.nmr.mgh.harvard.edu") {
       set req.http.host = "www.freesurfer.net";
       set req.backend = freesurfer;
     }

>From what I've been able to figure out the "if" looks for the old
virtual host and set's below it rewrite the header to look at the new
virtual host.  The last line in the vcl_recv function is a
return(_lookup) which I hope catches the request and handles.  If I
should be doing something else yet I don't know what.

      But I don't think it's working. I've looked at varnishlog output
and the backend fetch seems to be still using the old address.  And I
see no references to the new virtual host when I try to access the
pages via the old address in httpd's  access_log

      What am I doing wrong?  Tnx.

#This is a basic VCL configuration file for varnish.  See the vcl(7)
#man page for details on VCL syntax and semantics.
#
#Default backend definition.  Set this to point to your content
#server.
#
backend default {
   .host = "127.0.0.1";
   .port = "8080";
}

# local definition backend

backend freesurfer {
       .host = "127.0.0.1";
       .port = "8080";
}

#
#Below is a commented-out copy of the default VCL logic.  If you
#redefine any of these subroutines, the built-in logic will be
#appended to your code.
#
sub vcl_recv {
     if (req.request != "GET" &&
       req.request != "HEAD" &&
       req.request != "PUT" &&
       req.request != "POST" &&
       req.request != "TRACE" &&
       req.request != "OPTIONS" &&
       req.request != "DELETE") {
         /* Non-RFC2616 or CONNECT which is weird. */
         return (pipe);
     }
     if (req.http.host ~ "^sufer.nmr.mgh.harvard.edu") {
       set req.http.host = "www.freesurfer.net";
       set req.backend = freesurfer;
     }
     if (req.url ~ "^/fswiki") {
         remove req.http.Cookie;
     }
     if (req.url ~ "^/wiki/fswiki_htdocs") {
         remove req.http.Cookie;
     }
     if (req.request != "GET" && req.request != "HEAD") {
         /* We only deal with GET and HEAD by default */
         return (pass);
     }
     if (req.http.Authorization || req.http.Cookie) {
         /* Not cacheable by default */
         return (pass);
     }
     return (lookup);
}

-------------------------------------------------------------------------------
Chris Johnson               |Internet: johnson at nmr.mgh.harvard.edu
Systems Administrator       |Web:      http://www.nmr.mgh.harvard.edu/~johnson
NMR Center                  |Voice:    617.726.0949
Mass. General Hospital      |FAX:      617.726.7422
149 (2301) 13th Street      |"A good engineer never reinvents the wheel when
Charlestown, MA., 02129 USA |an existing one with modifications will do." Me
-------------------------------------------------------------------------------


The information in this e-mail is intended only for the person to whom it is
addressed. If you believe this e-mail was sent to you in error and the e-mail
contains patient information, please contact the Partners Compliance HelpLine at
http://www.partners.org/complianceline . If the e-mail was sent to you in error
but does not contain patient information, please contact the sender and properly
dispose of the e-mail.





More information about the varnish-misc mailing list