title: Difference in setting "proxy_set_header X-Forwarded-Proto $scheme;" outside and inside nginx location {} block
body: <p>I am trying to pass a secure cookie to node express JS app and using Nginx as web frontend. For successful implementation, nginx should pass 'X-Forwarded-Proto' header with value 'https'. The implementation of secure cookie will fail if I specify 'proxy_set_header X-Forwarded-For $scheme;' outside the nginx location {} block have proxy_pass statement.</p>
  
  <p>I want to know the difference between specifying proxy_set_header inside nginx location {} block and outside it.</p>
  
  <p>Secure Cookie will fail in this case:</p>
  
  <pre><code>server {
    proxy_set_header X-Forwarded-Proto $scheme;
    location {
      proxy_pass http://127.0.0.1:8080;
    }
  }
  </code></pre>
  
  <p>Secure cookie will pass in this case:</p>
  
  <pre><code>server {
    location {
      proxy_pass http://127.0.0.1:8080;
      proxy_set_header X-Forwarded-Proto $scheme;
    }
  }
  </code></pre>