当前位置:首页 > 服务器技术 > nginx

nginx 解决跨域需要几行

在指定的主机location 下添加以下语句便可;

如:

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;
}
}

原文:https://blog.51cto.com/jxlwc/2363517


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!