【发布时间】:2020-12-07 11:02:43
【问题描述】:
我在禁止 Varnish(版本 6.0.2)中的网址时遇到问题。
我正在尝试禁止这样的网址
/api/v2/product?param1=value1¶m2=value2param3=value3
如果我给出这个命令:
varnishadm ban req.url '~' '^/api/v2/product'
它工作正常,但它禁止所有以/api/v2/product 开头的网址,我只需要禁止那个特定的网址。
这些是我做过的尝试:
varnishadm ban req.url '~' '^/api/v2/product?param1=value1¶m2=value2param3=value3'
它不会返回任何错误但它不会禁止该网址
varnishadm ban req.url '~' '^/api/v2/product\?param1=value1'
我得到这个错误:
Unknown request.
Type 'help' for more info.
Syntax Error: Invalid backslash sequence
Command failed with error code 100
varnishadm ban req.url '~' '^/api/v2/product[?]param1=value1'
或
varnishadm ban req.url '~' '^/api/v2/product\\?param1=value1'
它不会返回任何错误但它不会禁止该网址
我也尝试过使用 == 不使用正则表达式
varnishadm ban req.url '==' '/api/v2/product?param1=value1¶m2=value2param3=value3'
它不会返回任何错误但它不会禁止该网址
我认为问题出在? 所以我尝试使用.* 而不是?
我试过了:
varnishadm ban req.url '~' '^/api/v2/product.*param1=value1'
它有效,它禁止所有以:^/api/v2/product&param1=value1 开头的网址,所以我试过了
varnishadm ban req.url '~' '^/api/v2/product.*param1=value1¶m2=value2'
它没有返回任何错误但它没有禁止该网址,所以我怀疑这次问题可能是&所以我尝试了:
varnishadm ban req.url '~' '^/api/v2/product.*param1=value1.*param2=value2'
但没什么,它不会返回错误,但不会禁止该网址。
任何使用 \ 转义特殊字符的尝试都会返回错误消息:
Unknown request.
Type 'help' for more info.
Syntax Error: Invalid backslash sequence
Command failed with error code 100
Varnish 手册说该软件使用 PCRE 标准,但我找不到为其编写正则表达式的方法。
任何帮助或建议将不胜感激。
谢谢 H2K
【问题讨论】: