我正在构建一个 Varnish 反向代理,它将在具有不同文件的 2 个服务器之间进行平衡。服务器 1 包含 500 个文件夹,范围从 000 - 499。服务器 2 有 500 个文件夹,范围从 500 - 999。
该场景与Squid 正则表达式文件夹范围
我对正则表达式感到困惑,因为我们可以得到 500 - 999,但不能得到 000 到 499
我的 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);
}
答案1
您正在匹配请求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;
}