Nginx configuration for enabling CORS -
i following reference trying have nginx accept cors. http://enable-cors.org/server_nginx.html
but no matter how config /etc/nginx/site-enable/default following. doesn't work. wrong configuration?
thanks.
> >
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html; index index.html index.htm; # make site accessible http://localhost/ server_name localhost; #add_header access-control-allow-origin *; # < needed header location / { # first attempt serve request file, # directory, fall displaying 404. #try_files $uri $uri/ =404; # uncomment enable naxsi on location # include /etc/nginx/naxsi.rules if ($request_method = 'options') { add_header 'access-control-allow-origin' '*'; # # om nom nom cookies # add_header 'access-control-allow-credentials' 'true'; add_header 'access-control-allow-methods' 'get, post, options'; # # custom headers , headers various browsers *should* ok aren't # add_header 'access-control-allow-headers' 'dnt,x-customheader,keep-alive,user-agent,x-requested-with,if-modified-since,cache-control,content-type'; # # tell client pre-flight info valid 20 days # add_header 'access-control-max-age' 1728000; add_header 'content-type' 'text/plain charset=utf-8'; add_header 'content-length' 0; 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-customheader,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-customheader,keep-alive,user-agent,x-requested-with,if-modified-since,cache-control,content-type'; } } }
the nginx cors-filter gets triggered when headers send within requests propagated in allowed-headers field. once send 1 header not mentioned in section, cors-filter nothing. did check request headers?
in addition, configuration not work put-requests. type of requests send? did check response-headers?
try set ipv6only=off;
Comments
Post a Comment