一般来说,cors跨域都是后端解决的,当然nginx也可以解决,配置如下:谨慎配置:
// 指定允许其他域名访问 参数 (* ,指定域,动态配置) *不允许携带认证头和cookies
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';
一般情况下加上面三个就可以了