ajax 请求后台数据接口时跨域,导致页面不能愉快的与数据交互。
需要使用的工具nginx
下载地址:http://nginx.org/en/download.html
使用nginx做反向代理,在server里面添加如下代码
location ~* /api/(.*) {
add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Headers token;
proxy_pass http://172.28.1.29:8010/$1 ;
}
解析链接中带api(自定义的链接)的请求
比如http://172.28.1.20:8020/api/user/list (实际请求路径为http://172.28.1.29:8010/user/list)