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 启动即可
正文完