产品社区:交流、吐槽和反馈 产品社区:交流、吐槽和反馈

返回

回复给跨域环境下Ngnix配置

不可用
分类


正在回复给:
跨域环境下Ngnix配置
nginx 跨域
答复
2018-03-13 16:17:17

现象:2018年3月13日,阳谷县教育云平台上传资源时出现“上传出错”

原因:跨域调用问题,Failed to load http://spare3.yangguedu.com/elearning-file/UploadServlet?fid=ftp-97ae9bd5-182a-4060-82be-502e67f817e8&username=123&date=2018%2d03%2d13+16%3a06%3a29&sid=5446EEAEC3E85C61BB6894AFE7D9BE07&fileId=file-b7c0ca26-2daa-41d8-be5e-8a3d830f556c: The 'Access-Control-Allow-Origin' header contains multiple values '*, http://yun.yangguedu.com', but only one is allowed. Origin 'http://yun.yangguedu.com' is therefore not allowed access.

解决方案:Nginx配置需要修改,在spare3.yangguedu.com.conf这个配置文件上添加下列配置即可。

add_header 'Access-Control-Allow-Methods' 'GET,OPTIONS,PUT,DELETE' always; 
add_header 'Access-Control-Allow-Credentials' 'true' always; 
add_header 'Access-Control-Allow-Origin' '$http_origin' always; 
add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,User-Agent,Keep-Alive,Content-Type,accept,origin,X-Requested-With' always; 
if ($request_method = OPTIONS ) { 
return 200; 
}
 
然后重新加载nginx服务。