这是一个超级丑陋的解决方案,因为特定的客户要求。
默认设置:对后端使用proxy_pass,如下所示(我已经删除了无用项)
server{
server_name customer.mysite.com;
location / {
proxy_pass http://backend.mysite.com/[customerId];
}
}到目前为止,一切都被改写了,我们都很好。但是,现在的要求是,如果客户没有任何查询参数,我们应该添加一些。
我最初的想法是在location = /中使用第二条规则来进行完全匹配,但是文档并不表示这个方法根本不关心查询参数。
那么,在nginx中有什么方法可以满足我的需求,还是必须找到其他的方法呢?
发布于 2020-02-13 17:47:47
要测试查询字符串是否不存在,可以使用$args块将if变量与空字符串进行比较。若要将此规则仅应用于URI /,请将其放置在location = /块中。
例如:
location / {
proxy_pass http://backend.example.com/customerId/;
}
location = / {
if ($args = "") { rewrite ^ /?query=foo last; }
proxy_pass http://backend.example.com/customerId/;
}关于if的使用,请参阅D6。
https://serverfault.com/questions/1002954
复制相似问题