nginx跨域配置

假设前端页面的地址为:

192.168.1.1/arcgis40/index.html

页面物理路径为:

X:\nginx-1.9.15\html\arcgis40

那么请求服务时,当ajax代码如下时:

 

$.ajax({
type: "GET",
dataType:"json",
url: "getVector/all/1/2/3",
success: function (data) {
alert(JSON.stringify(data));
},
error: function (msg) {
alert(JSON.stringify(msg));

}
});

实际发出的get地址为:192.168.1.1/arcgis40/getVector/all/1/2/3

 

那么在nginx.conf 中这样配置

location /arcgis40/getVector {
rewrite ^.+arcgis40/getVector/(.*)$ /$1 break;
include uwsgi_params;
proxy_pass http://localhost:5000/;
}

 

http://localhost:5000/  为服务端ip地址

服务端的实际接口地址为:http://localhost:5000/all/1/2/3

 

posted @ 2016-12-01 11:21  flanker521  阅读(432)  评论(0编辑  收藏  举报