'Using Variables With Nginx proxy_pass Directive

I'm trying to use variables with the Nginx proxy_pass directive to allow delayed DNS resolution, however, the following two configurations produce different results:

location /location1/ {
  proxy_pass https://location.domain.com:8000/;
}

location /location2/ {
  resolver 127.0.0.1 timeout=30s;
  set $location location.domain.com;
  proxy_pass https://$location:8000/;
}

The first location works as expected, while the second location results in just a blank white page. Does using variables with the proxy_pass directive introduce some headers or any other changes that might be breaking the second location? Or does the variable contain leading or trailing slashes or any other information other than an IP address? Looking at the above configuration one would expect both locations to work identically.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source