在HAproxy中,用一些数据替换传入的url。这是传入的路径:
/powerbi?redirectSuccessUrl=/reports我想要匹配:
/powerbi? 代之以
clientId=${clientId}&最后的结果必须是:
/powerbi?clientId=${clientId}&redirectSuccessUrl=/reports我试过这个
http-request set-path %[path, regsub(^/powerbi\?,/powerbi?clientId="${clientId}"&]但是得到两个问号(接近powerBi和在redirectSuccessUrl之前):
/powerbi?clientId=${clientId}&?redirectSuccessUrl=/reports如何匹配“?”跟瑞格一起?我试过“?”、“”、“”。这些都不符合问号。
发布于 2020-11-25 12:43:53
您不匹配?,因为在that中,它将uri的path部分与query string部分分离开来,而haproxy已经为您做到了这一点。您希望更改查询字符串,但更改路径。这就是为什么您的更改最终出现在?的错误方面。相反,使用http-request set-query,如下所示:
http-request set-query clientId=${clientId}&%[query]如果您可能希望根据原始uri是否有查询正确地设置查询,您可以尝试如下:
http-request set-query clientId=${clientId}&%[query] if { query -m found }
http-request set-query clientId=${clientId} unless { query -m found }这避免了在uri中没有查询字符串时尾随&。
或者,您可以使用set-uri尝试一些神奇的regexp并设置整个uri,但是要非常小心,请记住uri可能以relative uri (例如/foobar?arg1=val1&arg2=val2)或absolute uri (例如https://example.com:6789/foobar?arg1=val1&arg2=val2)的形式出现,然后使用适当的regexp来处理这两种情况要比像上面这样简单地使用set-path和set-query要困难得多。关于haproxy文档中相对和绝对uri的更多信息
回应意见的最新情况
您可以匹配路径部件和更改查询字符串,例如:
acl url_powerbi path_beg /powerbi
acl query_string_found query -m found
http-request set-query clientId=${clientId}&%[query] if url_powerbi query_string_found
http-request set-query clientId=${clientId} if url_powerbi !query_string_foundhttps://serverfault.com/questions/1043840
复制相似问题