title: Dynamic proxy_pass to $var with nginx 1.0
body: <p>I am trying to proxy a request to different targets depending on an environment variable. My approach was to put the target url into the custom variable $target and give this to proxy_pass. </p>
  
  <p>But using a variable with proxy_pass doesn't seem to work. This simple config leads to a "502 Bad Gateway" response from nginx.</p>
  
  <pre><code>server {
    listen   8080;
    server_name  myhost.example.com;
    access_log  /var/log/nginx/myhost.access.log;
    location /proxy {
      set $target http://proxytarget.example.com;
      proxy_pass $target;
    }
  }
  </code></pre>
  
  <p>The same config without the variable works:</p>
  
  <pre><code>server {
    listen   8080;
    server_name  myhost.example.com;
    access_log  /var/log/nginx/myhost.access.log;
    location /proxy {
      proxy_pass http://proxytarget.example.com;
    }
  }
  </code></pre>
  
  <p>Is it really not possible to use proxy_pass this way or am I just doing something wrong?</p>