實現
在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
來源:慕課網
本文原創發布於慕課網 ,轉載請注明出處,謝謝合作
