https://blog.csdn.net/q646926099/article/details/79082204
使用Ajax跨域请求资源,Nginx作为代理,出现:The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed 错误。
服务端允许跨域配置:
#region 设置允许跨域,允许复杂请求
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "\*");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,PATCH,OPTIONS");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, Authorization");
//HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
#endregion
————————————————
版权声明:本文为CSDN博主「xiaoqiu_net」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/q646926099/article/details/79082204
Nginx的配置:
add\_header 'Access-Control-Allow-Origin' '\*';
location / {
if ($request\_method = 'OPTIONS') {
add\_header Access-Control-Allow-Origin \*;
add\_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,PATCH,OPTIONS;
return 200;
}
proxy\_pass http://xx:8002/;
#proxy\_pass http://localhost:62249/;
————————————————
版权声明:本文为CSDN博主「xiaoqiu_net」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/q646926099/article/details/79082204
看上面错误提示,contains multiple values "*" 意思就是设置了2次跨域,但是只有一个是允许的,移除其中的任意一个就好了。如果服务器设置了允许跨域,使用Nginx代理里面就不需要了(或者就不用使用Nginx了)
手机扫一扫
移动阅读更方便
你可能感兴趣的文章