带有Varnish中的get参数的BAN网址

问题描述

我在禁止Varnish(版本6.0.2)中的网址时遇到问题。

我正试图禁止这样的网址

/api/v2/product?param1=value1&param2=value2param3=value3

如果我给出以下命令:

varnishadm ban req.url '~' '^/api/v2/product'

它可以正常工作,但是它禁止所有以/api/v2/product开头的网址,而我只需要禁止该特定网址。

这些是我所做的尝试:

varnishadm ban req.url '~' '^/api/v2/product?param1=value1&param2=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&param2=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&param2=value2'

它不会返回任何错误,但是它不会禁止该URL,因此我想这次可能是&了,所以我尝试了:

varnishadm ban req.url '~' '^/api/v2/product.*param1=value1.*param2=value2'

但是没有什么,它不会返回错误,但不会禁止该URL。

任何尝试使用\转义特殊字符的操作都会返回错误消息:

Unknown request.
Type 'help' for more info.
Syntax Error: Invalid backslash sequence

Command failed with error code 100

Varnish手册说该软件使用PCRE标准,但是我找不到为它编写正则表达式的方法。

任何帮助或建议将不胜感激。

谢谢 H2K

解决方法

我发现了问题,有一个

set req.url = std.querysort(req.url);

正在更改使get参数无效的正则表达式的代码中。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...