nginx配置跨域,代理同源

207 阅读1分钟

前端把api的baseurl写成和前端部署域名相同
再nginx将/api转发到真实服务器地址

  location /api {
         proxy_set_header Origin "http://xxx.xxx.com";//真实后端ip
         proxy_set_header Host "http://xxx.xxx.com";
         rewrite ^/api/(.*) /$1 break;
         proxy_pass "http://xxx.xxx.com";
         }