实现
在nginx.conf中编辑
server { location / { root html; index index.html index.htm; //允许cros跨域访问 add_header 'Access-Control-Allow-Origin' *; } //自定义本地路径 location /apis { rewrite ^.+apis/?(.*)$ /$1 break; include uwsgi_params; proxy_pass http://e.apix.cn; } }
然后我把项目部署在nginx的html根目录下,在ajax调用时设置url从http://e.apix.cn/apixanalysis/mobile/grant/phone/smsCode/verify
变为/apis/apixanalysis/mobile/grant/phone/smsCode/verify
然后成功解决
总结
- nginx解决跨域问题,只需要修改一下配置文件即可。超方便简单
作者:蛤伯爵
链接:http://www.imooc.com/article/12591
来源:慕课网
本文原创发布于慕课网 ,转载请注明出处,谢谢合作