We haven an internal JIRA server running. And I am developing a UI web app with the REST api provided.
My angularjs UI web app runs at http://127.0.0.1:9000
which hits http://localhost/jira-api/rest/api/2/...
To deal with cross domain issues I setup ngnix with below configuration.
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;
}
}
}
But this gives me an error for OPTIONS request: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin http://127.0.0.1:9000
is therefore not allowed access.
The response headers of the OPTIONS request don't actually have any of the headers that I set above:
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
Is something wrong with the configuration??