当我在javascript中通过XMLHttpRequst请求一个xml文件时,就提示标题的错误,网上找了一些网页,有的说要修改源码,有的说需要添加nginx的其他模块,最后再分析nginx.conf文件时,可以通过add_headers 去添加HTTP应答的返回选项
在nginx.conf文件中,在具体的location 块中添加即可
location /xxx{
root /var;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
add_header 'Access-Control-Allow-Methods' 'GET,POST';
add_header 'Access-Control-Allow-Credentials' 'true';
}
另外注意点,就是通过nginx -s reload这个貌似不生效,重启nginx是生效的,当面的问题也得到解决