server{
# 监听80端口
listen 80;
# 域名为:a.com
server_name a.com;
location /{
# 把所有的请求都转发到该地址下
proxy_pass http://127.0.0.1:8081/;
}
# 增加代理(需要调用的服务器的地址,请求的前缀)
location /server{
proxy_pass http://127.0.0.1:8080/ajaxServer/;
}
}
// 自定义头的跨域
function getHeader(){
$.ajax({
type: 'get',
url: '/server/header',
// 发送自定义头的两种方式
headers:{
"x-header1":"AAA"
},
beforeSend:function(xhr){
xhr.setRequestHeader("x-header2","BBB")
},
success: function(data){
console.log(data);
},
});
}
========================
客户端访问的原地址:http://127.0.0.1:8081/ajaxClient/
客户端访问的新地址:http://a.com/ajaxClient/
触发跨域请求后报错:jquery-1.8.3.min.js:2 GET http://a.com/server/header 404 (Not Found)
location /{ location /server{ “{”前面要有空格;你服务器要有header地址