Search code examples
nginxkubernetesproxypass

custom variable for nginx proxypass


I am trying to have proxy_pass working with custom variable

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

and it does not work. However:

location  / {

        proxy_pass          http://destination;
}

works perfectly fine. What do I do wrong?


Solution

  • The best solution i found uses no variable at all. Using variable for proxy_pass requires full domain names. Here is my solution:

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