nginx處理跨域請求


實現

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM