NGINX解决跨域问题 Cors方案

在NGINX配置文件XXX.conf里面 server { listen 80; server_name www.carry.com; #加入以下信息 #nginx解决跨区问题 if($http_origin ~ http://(.*).carry.com){ set $allow_url $http_origin; } #是否允许请求带有验证信息 add_header Access-Control-Allow-Creadentials true; #允许跨域访问的域名,可以使一个域的列表,也可以是通配符* add_header Access-Control-Allow-Origin $allow_url; #允许脚本访问的返回头 add_header Access-Control-Allow-Headers ‘x-requested-with,content-type,Cache-Control,Pragma,Date,x-timestamp’; #允许使用的请求方法,以逗号隔开 add_header Access-Control-Allow-Methods ‘POST,GET,OPTIONS,PUT,DELETE’; #允许自定义的头部,以逗号隔开,大小写不敏感 add_header Access-Control-Expose-Headers ‘WWW-Authenticate,Server-Authorization’; #P3P支持跨域cookie操作 add_header P3P ‘policyref="/w3c/p3p.xml", CP=“NOI DSP PSAa OUR BUS IND ONL UNI COM NAV INT LOC”’;

add_header test 1;
经验分享 程序员 微信小程序 职场和发展