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.

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);

}
share|improve this question

1 Answer 1

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;
}
share|improve this answer

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.