Nginx+uwsgi+django 解决Ajax跨域

Django + Nginx + uwsgi 项目使用ajax 外部请求跨域问题:

问题描述:

Font from origin 'http://cdn.xxxx.com' has been blocked from loading by Cross-Origin Resource Sharing policy: 
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.xxxx.com' 
is therefore not allowed access.

解决方案:
在Nginx.conf 添加:

如果不知道配置文件路径: nginx -t 列出配置文件路径

add_header Access-Control-Allow-Origin http://www.xxxx.com;
add_header Access-Control-Allow-Headers Origin,X-Requested-With,Content-Type,Accept;
add_header Access-Control-Allow-Methods POST,GET;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Origin http://www.xxxx.com;
add_header Access-Control-Allow-Headers Origin,X-Requested-With,Content-Type,Accept;
add_header Access-Control-Allow-Methods POST,GET;
add_header Access-Control-Allow-Credentials true;

你可能感兴趣的:(Django,Python)