title: Nginx proxy_pass to variable with trailing slash fails
body: <p>I'm having an issue where I need to make the proxy_pass a variable, but when I make it a variable, it fails to resolve correctly on the backend server</p>
  
  <pre><code>nginx -v
  nginx version: nginx/1.6.2
  </code></pre>
  
  <p>This is the working one:</p>
  
  <pre><code>  server {
      listen 443 ssl;
      ssl on;
      server_name api.hostname.com;
  
      include ssl_params;
  
      location = /v1 {
        return 302 /v1/;
      }
  
      location /v1/ {
        proxy_pass        http://internal-api.hostname.com.us-east-1.elb.amazonaws.com/;
        proxy_set_header  Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
      }
  
    }
  </code></pre>
  
  <p>This is a broken one</p>
  
  <pre><code>  server {
      listen 443 ssl;
      ssl on;
      server_name api.hostname.com;
  
      include ssl_params;
  
      location = /v1 {
        return 302 /v1/;
      }
  
      location /v1/ {
        resolver 10.0.0.2;
        set $backend "http://internal-api.hostname.com.us-east-1.elb.amazonaws.com/";
        proxy_pass        $backend;
        proxy_set_header  Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
      }
  
    }
  </code></pre>
  
  <p>The backend results for <a href="https://api.hostname.com/v1/profile" rel="nofollow">https://api.hostname.com/v1/profile</a> on the working one is:</p>
  
  <pre><code>&lt;-- GET /profile
  --&gt; GET /profile 200 16ms 349b
  </code></pre>
  
  <p>But on the broken one</p>
  
  <pre><code>&lt;-- GET /
  --&gt; GET / 401 1ms 12b
  </code></pre>
  
  <p>I've tried with:</p>
  
  <pre><code>set $backend "internal-api.hostname.com.us-east-1.elb.amazonaws.com";
  proxy_pass http://$backend/
  
  set $backend "internal-api.hostname.com.us-east-1.elb.amazonaws.com/";
  proxy_pass http://$backend/
  </code></pre>
  
  <p>Any time I'm using variables in the proxy_pass, it forwards everything to / (root) on the backend, definitely not what I was intending.</p>