nginx proxypass 的自定义变量

custom variable for nginx proxypass

我正在尝试让 proxy_pass 使用自定义变量

location  / {
        set $proxy_pass_dest  destination;
        proxy_pass          http://$proxy_pass_dest;
}

而且它不起作用。然而:

location  / {

        proxy_pass          http://destination;
}

工作得很好。我做错了什么?

我找到的最佳解决方案根本不使用任何变量。为 proxy_pass 使用变量需要完整的域名。这是我的解决方案:

  if ($arg_somearg) {
                proxy_pass          http://destination;
  }
  if ($arg_otherarg) {
                proxy_pass          http://destination;
  }
  proxy_pass          http://destination2;