前端api请求跨域nginx代理解决

需求描述:
前端本地(react)项目api访问线上地址,提示跨域错误!

配置nginx代理api请求,"/base/"为本地请求路径

location /base/ {
          proxy_http_version 1.1;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_pass http://www.baidu.com/;
          #add_header Access-Control-Allow-Origin *;
          #add_header Access-Control-Allow-Methods "POST, GET, OPTIONS";
          #add_header Access-Control-Allow-Headers "Origin, Authorization, Accept";
          #add_header Access-Control-Allow-Credentials true;
        }

注意本地htttp协议或https要相对应

你可能感兴趣的:(前端api请求跨域nginx代理解决)