JeremyJR
JeremyJR

Reputation: 151

Regex to match host request

Given this VCL code in Varnish 3.0.2:

sub vcl_recv {
  if (req.http.host !~ "^(?i)(www|m|mobile)\.example\.com$" || req.http.host !~ "^(?i)example\.com$") {
    error 403 "Forbidden";
  }
  return(lookup);
}

can anyone explain why I'm getting 403s on "www.example.com"?

Thanks

Upvotes: 0

Views: 3319

Answers (1)

stema
stema

Reputation: 92976

I don't know varnish and its syntax, but I interpret || to be an logical OR. So www.example.com does not match the second alternative ==> it is true and you enter the if.

Probably you wanted a logical AND? If both is not true, then 403?

So try:

if (req.http.host !~ "^(?i)(www|m|mobile)\.example\.com$" && req.http.host !~ "^(?i)example\.com$") {
    error 403 "Forbidden";
  }

Upvotes: 5

Related Questions