光油正则expression式文件夹范围

我正在构build一个清反向代理,它将在两台具有不同文件的服务器之间进行平衡。 服务器1包含500个范围从000 – 499的文件夹。服务器2有500个文件夹,范围从500 – 999。

Senario和Squid Regular Expression Folder Range完全一样

我正在努力正则expression式,因为我们可以达到500 – 999,但不是000到499

我的configuration文件如下Varnish 3.0.2目前进入文件夹500 – 999第二个盒子没有问题,但没有在第一个框。

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

您正在匹配req.http.host ,它是您的请求的主机名。 我假设你想匹配一个url中的文件名。

如果您的文件名称URL看起来像“/files/012/filename.ext”,您可以匹配以下VCL:

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