nginx跨域配置,如下配置需要添加到location节点下,要注意options请求可能可能会被分配到的location节点
Access-Control-Allow-Methods中配置的方法要大写
#对于非简单请求
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'DELETE,POST';
add_header 'Access-Control-Allow-Headers' 'Content-Type';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
#对于简单请求,一般就是get
add_header 'Access-Control-Allow-Origin' '*';