1

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
  • 636
  • 2
  • 10
  • 30
  • 1
    Does it answer your question https://stackoverflow.com/a/8635267/11714114 ? – mario Dec 20 '19 at 17:13
  • 1
    It depends what *destination* represents. If there is a domain name, you will need a resolver and if there is a URI part, you will need to specify the full URI. – Richard Smith Dec 20 '19 at 20:49
  • There is domain name. It is all in kubernetes and `http://destination;` works fine - resolver is able to do the job. It does not work for the variable `$proxy_pass_dest` and I am struggling to find out why. – Wojtas.Zet Dec 23 '19 at 08:44
  • ok I have just confirmed it in nginx pod running in kubernetes (using variable `$proxy_pass_dest:`): `2019/12/23 09:05:53 [error] 6#6: *157 no resolver defined to resolve destination` – Wojtas.Zet Dec 23 '19 at 09:08
  • If I use `http://destination;` there is no error in the nginx.log so the name gets resolved. Obviously problem is limited to using the variable. I tried `resolver kube-dns.kube-system.svc.cluster.local` `resolver coredns.kube-system.svc.cluster.local ` `resolver 127.0.0.1` and no luck. Ended up with workaround not using variable at all. – Wojtas.Zet Dec 23 '19 at 10:59
  • ok it works only with full names and variable: `http://destination.production.svc.cluster.local` which I got from nslookup - does not work with just `http://destination` – Wojtas.Zet Dec 23 '19 at 11:11
  • Did you need both, the resolver and full named variable when you used variable approach? – Mikolaj Oct 06 '22 at 07:34

1 Answers1

0

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
  • 636
  • 2
  • 10
  • 30