0%

工作中经常会遇到 No ‘Access-Control-Allow-Origin’ header is present on the requested resource 这样的跨域错误,此时需要给Nginx服务器配置响应的header参数:

一般解决方案

修改nginx配置文件:

1
2
3
4
5
6
7
8
9
location / {  
add_header Access-Control-Allow-Origin "*";
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,Authorization';

if ($request_method = 'OPTIONS') {
return 204;
}
}
阅读全文 »

  今天是愚人节,在这一天开通博客的确是个值得纪念的日子,从事技术这么多年感觉还是需要有个小树洞藏点私货,如果你不小心发现了这个博客,很高兴遇到你!