nginx 跨域请求相关内容
if ( $request_method = 'OPTIONS' ) {
add_header Access-Control-Allow-Origin $http_origin;
add_header Access-Control-Allow-Headers Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,X-Data-Type,X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS,HEAD,PUT;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Headers X-Data-Type,X-Auth-Token;
return 200;
}
————————————————
版权声明:本文为CSDN博主「肺鱼的等待」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/hyneria_hope/article/details/78813044
https://blog.csdn.net/yanggd1987/article/details/80334885
https://segmentfault.com/a/1190000012550346?utm_source=tag-newest
静态资源跨域
location /media {
alias /data/aisp/media/;
add_header 'Access-Control-Allow-Origin' '*';
}
参考资料:如何通过 Nginx 解决跨域问题_nginx 跨域请求_一路孙的博客-CSDN博客
Cors跨域(三):Access-Control-Allow-Origin多域名? - 墨天轮
map $http_origin $corsHost {
default 0;
"~https://www.itbiancheng.com" https://www.itbiancheng.com;
"~http://love.itbiancheng.com" http://love.itbiancheng.com;
}
server
{
listen 80;
server_name www.itbiancheng.com;
root /nginx;
location /
{
add_header Access-Control-Allow-Origin $corsHost;
}
}