title: Nginx load balancer error when 302 is used
body: <p>I've an nginx container used as load balancer, for a streaming DASH-based service.There are also 3 VM used as upstream servers.
  This is nginx config file:</p>
  
  <pre><code>upstream cdn-audio {
          server 192.168.99.103:9500;
          server 192.168.99.104:9500;
          server 192.168.99.105:9500;
     }
  
  upstream cdn-video {
  
          server 192.168.99.103:9500;
          server 192.168.99.104:9500;
          server 192.168.99.105:9500;
      }
  
  
  server {
  
  listen 80;
  server_name 172.17.0.1;
  access_log /var/log/nginx/acces.log main;
  
  location = /LynyrdSkynyrdFreebirdAudio.mp4 {
  
  #           proxy_pass http://192.168.99.103:9500;
  
  # proxy_pass http://cdn-audio/LynyrdSkynyrdFreebirdAudio.mp4;
  add_header X-Upstream  $upstream_addr;
  add_header Host $host;
  if ($request_method = OPTIONS) {
          add_header Access-Control-Allow-Origin '*';
          add_header Access-Control-Allow-Headers "Authorization,Range";
          add_header Access-Control-Allow-Credentials "true";
          add_header Content-Length 0;
          add_header Content-Type text/plain;
          add_header Host $host;
          return 200;
      }
  
         return 302 $scheme://cdn-audio/LynyrdSkynyrdFreebirdAudio.mp4;
  
          }
  
  location = /LynyrdSkynyrdFreebirdVideo.mp4 {
  
  add_header X-Upstream  $upstream_addr;
  #  proxy_pass http://cdn-audio/LynyrdSkynyrdFreebirdVideo.mp4;
  add_header Host $host;
  
  
  if ($request_method = OPTIONS) {
          add_header Access-Control-Allow-Origin '*' ;
          add_header Access-Control-Allow-Headers "Authorization,Range";
          add_header Access-Control-Allow-Credentials "true";
          add_header Content-Length 0;
          add_header Content-Type text/plain;
          add_header Host $host;
          return 200;
  }
  
  
  #       proxy_pass http://cdn-video$request_uri;
  
  #       proxy_pass http://192.168.99.103:9500;
  
         return 302 $scheme://cdn-video/LynyrdSkynyrdFreebirdVideo.mp4;
  #       add_header X-Upstream  $upstream_addr;
  
          }
  
     }
  </code></pre>
  
  <p>From an html page hosted in another container ( a frontend container), first there is a HTTP OPTIONS request to :/LynyrdSkynyrdFreebirdAudio.mp4 and :/LynyrdSkynyrdFreebirdVideo.mp4, because of cross site origin.
  Then the response header is shown in the config code.</p>
  
  <p>Then, when i try to redirect request to one of my three upstream server, there is an error:</p>
  
  <ul>
  <li>XMLHttpRequest cannot load
  http: // localhost:9200/LynyrdSkynyrdFreebirdVideo.mp4. Redirect from
  'http: // localhost:9200/LynyrdSkynyrdFreebirdVideo.mp4' to
  'http: // cdn-video/LynyrdSkynyrdFreebirdVideo.mp4' has been blocked by
  CORS policy: Request requires preflight, which is disallowed to
  follow cross-origin redirect.</li>
  <li>XMLHttpRequest cannot load
  http: // localhost:9200/LynyrdSkynyrdFreebirdAudio.mp4. Redirect from
  'http: // localhost:9200/LynyrdSkynyrdFreebirdAudio.mp4' to
  'http: // cdn-audio/LynyrdSkynyrdFreebirdAudio.mp4' has been blocked by
  CORS policy: Request requires preflight, which is disallowed to
  follow cross-origin redirect.</li>
  </ul>
  
  <p>Please note that i made </p>
  
  <pre><code>curl -I -X OPTIONS http://192.168.99.103:9500/LynyrdSkynyrdFreebirdAudio.mp4
  </code></pre>
  
  <p>This is response:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Server: nginx/1.11.8
  Date: Wed, 25 Jan 2017 16:31:28 GMT
  Content-Length: 0
  Connection: keep-alive
  Allow: GET, HEAD, POST, PUT, DELETE, OPTIONS
  Access-Control-Allow-Origin: *
  Access-Control-Allow-Headers: Range
  </code></pre>
  
  <p>Can you help me to solve this problem?</p>