跨域报错
The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:8080, *', but only one is allowed. Origin 'http://localhost:8080' is therefore not allowed access.
原因 可能是django 和nginx中都配置了跨域导致的
去掉nginx 配置中的跨域就可了
原来nginx配置
server {
listen 80; # 监听端口
server_name 3.1931.15.12 ; # 站点域名
autoindex on;
charset utf-8;
#charset koi8-r; # 编码格式
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
#虚拟主机访问日志定义
access_log /var/log/nginx/nginx_access.log; # 虚机访问日志存放地
error_log /var/log/nginx/nginx_error.log; # 虚机访问错误日志存放地
client_max_body_size 75M;
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass 172.30.0.12:8111;
#proxy_pass http://172.30.0.12:8111/; # 代理转发地址
}
location /static/ {
#autoindex on;
alias /var/www/volley/static/;
}
error_page 500 502 503 504 /50x.html;
}
更改后配置
server {
listen 80; # 监听端口
server_name 94.191.15.122 ; # 站点域名
autoindex on;
charset utf-8;
access_log /var/log/nginx/nginx_access.log; # 虚机访问日志存放地
error_log /var/log/nginx/nginx_error.log; # 虚机访问错误日志存放地
client_max_body_size 75M;
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass 172.30.0.12:8111;
#proxy_pass http://172.30.0.12:8111/; # 代理转发地址
}
location /static/ {
#autoindex on;
alias /var/www/volley/static/;
}
error_page 500 502 503 504 /50x.html;
}
下面三行是增加跨域的 去掉
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';