1、使用场景:要访问其他域名上的数据(通常接口),web端报跨域错误
2、重要代码:
http {
###start####
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
###end ###
}
3、重要位置:请求对象域名的服务器,如向http://www.api.com/db.jso接口请求数据,就需要把上面代码放在api这台提供服务的机器的nginx的http模块中,注意分号
4、重新按最新的配置文件启动nginx启动即可
文章评论