[JavaScript] Nginx实现跨域设置

假如跨域请求的接口为:http://xxx.cn/was5/web/search

Nginx配置:

在conf/nginx.conf文件中

location / {
    root   html;
    index  index.html index.htm;
}

 

后面增加

location /was5{
    proxy_pass   http://xxx.cn;
}

配置之后,将js请求接口改为:/was5/web/search 

重启Nginx服务,浏览器访问http://localhost即可,默认端口80,可在conf/nginx.conf更改端口

 

posted on 2019-01-05 22:57  晏过留痕  阅读(1326)  评论(0编辑  收藏  举报