django - Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers -



django - Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers -

i have 2 separate server,one nginx node,and 1 django django-rest-framework build ding rest api,nginx responsible rest api request,node takes care of client request, utilize polymer frontend .below brief description:

machine one:

nginx:192.168.239.149:8888 (api listening address) forwards 192.168.239.147:8080 node:192.168.239.149:80 (client listening address)

machine two:

unicorn:192.168.239.147:8080(listening address)

the process when request comes in,node server(192.168.239.149:80) responses homecoming html,in html ajax request inquire api server(nginx:192.168.239.149:8888 forwards unicorn:192.168.239.147:8080),and unicorn(192.168.239.147:8080) returns result.

but there cors problem,i read lot article,and many people met same questions,i tried many methods,but no help.still error.

what :

that is:

xmlhttprequest cannot load http://192.168.239.149:8888/article/. request header field access-control-allow-origin not allowed access-control-allow-headers.

what :

polyme core-ajax

<core-ajax auto headers='{"access-control-allow-origin":"*","x-requested-with": "xmlhttprequest"}' url="http://192.168.239.149:8888/article/" handleas="json" response="{{response}}"></core-ajax>

nginx:

http { include mime.types; default_type application/octet-stream; access_log /tmp/nginx.access.log; sendfile on; upstream realservers{ #server 192.168.239.140:8080; #server 192.168.239.138:8000; server 192.168.239.147:8080; } server { hear 8888 default; server_name example.com; client_max_body_size 4g; keepalive_timeout 5; location / { add_header access-control-allow-origin *; try_files $uri $uri/index.html $uri.html @proxy_to_app; } location @proxy_to_app{ add_header access-control-allow-origin *; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_set_header host $http_host; #proxy_set_header x-real-ip $remote_addr; proxy_redirect off; proxy_pass http://realservers; } } }

node:

app.listen(80, function() { console.log('server.js running'); });

unicorn:

return response(serializer.data,headers={'access-control-allow-origin':'*', 'access-control-allow-methods':'get', 'access-control-allow-headers':'access-control-allow-origin, x-requested-with, content-type', })

because,i have not much experience on cors,and want understand thoroughly,can point out doing wrong here,i give thanks much!

wow,so excited,i sovled self,what wrong here request header sent not included in nginx config add_header 'access-control-allow-headers'

complete nginx config:

http { include mime.types; default_type application/octet-stream; access_log /tmp/nginx.access.log; sendfile on; upstream realservers{ #server 192.168.239.140:8080; #server 192.168.239.138:8000; server 192.168.239.147:8080; } server { hear 8888 default; server_name example.com; client_max_body_size 4g; keepalive_timeout 5; location / { add_header access-control-allow-origin *; add_header 'access-control-allow-credentials' 'true'; add_header 'access-control-allow-methods' 'get, post, put, delete, options'; add_header 'access-control-allow-headers' 'access-control-allow-orgin,xmlhttprequest,accept,authorization,cache-control,content-type,dnt,if-modified-since,keep-alive,origin,user-agent,x-mx-reqtoken,x-requested-with'; try_files $uri $uri/index.html $uri.html @proxy_to_app; } location @proxy_to_app{ add_header access-control-allow-origin *; add_header 'access-control-allow-credentials' 'true'; add_header 'access-control-allow-methods' 'get, post, put, delete, options'; add_header 'access-control-allow-headers' 'access-control-allow-orgin,xmlhttprequest,accept,authorization,cache-control,content-type,dnt,if-modified-since,keep-alive,origin,user-agent,x-mx-reqtoken,x-requested-with'; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_set_header host $http_host; #proxy_set_header x-real-ip $remote_addr; proxy_redirect off; proxy_pass http://realservers; } } }

because request :

core-ajax auto headers='{"access-control-allow-origin":"*","x-requested-with": "xmlhttprequest"}' url="http://192.168.239.149:8888/article/" handleas="json" response="{{response}}"></core-ajax>

i didnt include access-control-allow-origin , xmlhttprequest header nginx config access-control-allow-headers,so problem.

i hope useful whom has same problem!

django http cors polymer django-rest-framework

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -