Naive use of regsub to set req.backend

Pierre Fortin Carrier pcarrier at openfares.com
Mon May 5 21:24:04 CEST 2008


Hello,

I am currently using Varnish 1.1.2 in front of a load balancer with
impressive success.  Congratulation for this jewel.

I recently got charmed by the idea of using VCL to send some request
directly to a specific node (bypassing the LB) for testing purpose.

I seek to avoid the advertised method proposed in VCL man page that will
lead to too much elsif in my setup.

My current attempt seem to lead to a dead end:

  backend LB {
    set backend.host = "10.0.0.1";
    set backend.port = "8080";
  }

  backend node1 {
    set backend.host = "10.0.0.10";
    set backend.port = "80";
  }

  backend node2 {
    set backend.host = "10.0.0.20";
    set backend.port = "80";
  }

  sub vcl_recv {
    if (req.http.host ~ "^webapp\.example\.com$") {
      set req.backend = LB;
    } elsif (req.http.host ~ "^.+\.webapp\.example\.com$") {
      set req.backend = regsub(req.http.host, "\.webapp\.example\.com", "");
      set req.http.host = "webapp.example.com";
    } else {
      error 404 "This website isn't living here";
    {

Symptom:
  Varnish refuse to start and complaint about:
  varnishExpected ';' got '('
    (on the regsub line)

>From what I understand I don't understand.  Did I missed something
obvious here?

Any hint would be much appreciated.

Thanks,
Pierre



More information about the varnish-misc mailing list