http {
......
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
......
}
或者
http {
if ($http_origin ~ https://xxx.com) {
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Credentials' "true";
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
}
....
}
这样就可以实现GET,POST,OPTIONS的跨域请求的支持
也可以 add_header Access-Control-Allow-Origin http://xxx.com; --指定允许的url;
配置项详细解释:w3c-Cross-Origin Resource Sharing
转载于:https://blog.51cto.com/haoyonghui/2112513
本文介绍如何通过Nginx配置实现GET、POST及OPTIONS等请求方式的跨域支持。提供了具体的Nginx配置示例,包括设置Access-Control-Allow-Origin、Access-Control-Allow-Headers和Access-Control-Allow-Methods等头部字段。
6668

被折叠的 条评论
为什么被折叠?



