varnish - VCL中的 "~"符号是什么意思?

标签 varnish

我发现如果语句“〜” ,这在 Varnish vcl 中使用

if (req.url ~ "phpMyAdmin") {
    return (pass);
}

我了解它像 == 一样工作,像 in_array()
if ( req.http.User-Agent ~ "(Android|iPhone|iPad|BlackBerry|SAMSUNG)") 
   return(pass);
}

有人可以解释一下这是什么意思吗?
它也是默认的php运算符吗?和 == 有什么区别

最佳答案

根据 official documentation~ 匹配运算符
== 比较两个值,如果相等则返回真
~ 根据正则表达式检查值,如果值匹配则返回 true

~ Match. Can either be used with regular expressions or ACLs.


# match an IP address against an ACL
if (client.ip ~ local) {
  return (pipe);
} 

Varnish uses Perl-compatible regular expressions (PCRE). To send flags to the PCRE engine, such as to do case insensitive matching, add the flag within parens following a question mark, like this:


# If host is NOT example dot com..
if (req.http.host !~ "(?i)example\.com$") {
    ...
}

关于varnish - VCL中的 "~"符号是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52201433/

相关文章:

caching - Varnish 在不同浏览器上的作用不同,为什么?

varnish - Varnish 4.0 中的 obj.ttl

caching - Varnish 4每120秒连续重试一次后端请求

virtualhost - 通过 Varnish 的多个虚拟主机,如果服务不正确的后端

vcl - 如何告诉 Varnish 缓存特定的文件类型

varnish - 如何重定向特定的 url - Varnish?

http - 我可以改变自定义 header 吗?

php - 我如何让 Varnish 4 缓存所有内容而不考虑缓存控制 header 和 cookie

php - Varnish 不适用于WooCommerce

symfony - 登录 ESI 组件中的缓存页面会重定向到/_internal/secure/.../none.html