title: ngnix CORS configuration for JIRA api not working
body: <p>We haven an internal JIRA server running. And I am developing a UI web app with the REST api provided. </p>
  
  <p>My angularjs UI web app runs at <code>http://127.0.0.1:9000</code> which hits <code>http://localhost/jira-api/rest/api/2/...</code></p>
  
  <p>To deal with cross domain issues I setup ngnix with below configuration. </p>
  
  <pre><code>worker_processes  1;
  events {
      worker_connections  1024;
  }
  http {
      upstream jiraserver {
          server myjira.com;
      }
      server {
          listen localhost:80;
          server_name localhost;
  
          location /jira-api {
              rewrite  ^/jira-api/(.*) /$1 break;
  
              if ($request_method = 'OPTIONS') {
                  add_header 'Access-Control-Allow-Origin' '*';
                  add_header 'Access-Control-Allow-Credentials' 'true';
                  add_header 'Access-Control-Max-Age' 1728000;
                  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                  add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since';
  
                  add_header 'Content-Length' 0;
                  add_header 'Content-Type' 'text/plain charset=UTF-8';
  
                  return 204;
              }
  
               if ($request_method = 'POST') {
  
                  add_header 'Access-Control-Allow-Origin' '*';
                  add_header 'Access-Control-Allow-Credentials' 'true';
                  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                  add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
  
               }
  
               if ($request_method = 'GET') {
  
                  add_header 'Access-Control-Allow-Origin' '*';
                  add_header 'Access-Control-Allow-Credentials' 'true';
                  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                  add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
  
               }
  
              proxy_pass http://jiraserver;
          }
      }
  }
  </code></pre>
  
  <p>But this gives me an error for OPTIONS request: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin <code>http://127.0.0.1:9000</code> is therefore not allowed access. </p>
  
  <p>The <em>response headers</em> of the OPTIONS request don't actually have any of the headers that I set above:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Server: nginx/1.6.2
  Date: Mon, 22 Sep 2014 12:35:39 GMT
  Content-Type: text/html;charset=UTF-8
  Content-Length: 0
  Connection: keep-alive
  X-AREQUESTID: 515x609530x4
  X-Seraph-LoginReason: OK
  X-ASESSIONID: 10iojgl
  X-AUSERNAME: someone
  </code></pre>
  
  <p>Is something wrong with the configuration??</p>