nginx配置跨域请求

小兔叽 可爱的博主

时间: 2020-10-17 阅读: 607 字数:736

{}
修改文件中nginx.conf ,并添加以下配置

一、找到nginx的配置文件

修改文件中nginx.conf 添加配置

 server {
            listen   80;   #监听端口
            server_name  localhost;   #监听地址       
            location  / {       #请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。
              # root /Users/shaojiaxi/Desktop/web-shaojiaxi;
            #    index el.html;
            proxy_pass http://127.0.0.1:8080/; ##修改为前端访问地址
            proxy_redirect default;
            }
       
        location /api/ {
            proxy_pass http://127.0.0.1:8888/;##修改为后台访问地址
            proxy_redirect default;
        }
           
    }

配置完成之后,重启nginx。

前台地址就成为:localhost

后台地址就成为:localhost/api/

本文章网址:https://www.sjxi.cn/detil/2d1842bbb68b47fcbc7ca129db1e0183

最新评论

当前未登陆哦
登陆后才可评论哦

湘ICP备2021009447号