custom variable for nginx proxypass

12/20/2019

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?

-- Wojtas.Zet
kubernetes
nginx
proxypass

1 Answer

12/30/2019

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;
-- Wojtas.Zet
Source: StackOverflow