0

I am building a Varnish reverse proxy which will balance between 2 servers with different files. Server 1 contains 500 folders ranging from 000 - 499. Server 2 had 500 folders ranging from 500 - 999.

The senario is exactly the same as Squid Regular Expression Folder Range

I'm struggling with the Regular expression as we can get to 500 - 999 but not 000 to 499

My config file is as follows for Varnish 3.0.2 which currently goes to folder 500 - 999 without issues on the second box but nothing on the first box.

# access control list for "purge": open to only localhost and other local nodes
acl purge {
        "localhost";
}

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

backend images02 {
  .host = "images02.test.local";
  .port = "80";
  .probe = { .url = "/server_status.php"; .interval = 5s; .timeout = 1s; .window = 5;.threshold = 3; }
}

backend images03 {
  .host = "images03.test.local";
  .port = "80";
  .probe = { .url = "/server_status.php"; .interval = 5s; .timeout = 1s; .window = 5;.threshold = 3; }
}

sub vcl_recv {
# Serve objects up to 2 minutes past their expiry if the backend
# is slow to respond.
   set req.grace = 120s;

# This uses the ACL action called "purge". Basically if a request to
# PURGE the cache comes from anywhere other than localhost, ignore it.
        if (req.request == "PURGE")
            {if (!client.ip ~ purge)
                {error 405 "Not allowed.";}
            return(lookup);}



     if (req.http.host ~ "[0-4]{1}[0-9]{1}[0-9]{1}" )
         { set req.backend = images02; }
     else
         { set req.backend = images03; }

       return(lookup);

}

1 Answer 1

2

You are matching req.http.host which is the hostname of your request. I assume that you want to match file names in a url.

If your file name urls would look like "/files/012/filename.ext" you could match with the following VCL:

if ( req.url ~ "^/files/[0-4][0-9][0-9]/" ) {
  set req.backend = images02;
}
else {
  set req.backend = images03;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .