反向代理到接口地址
#意思就是只要含有"api"的请求,都转发到接口地址去请求
location /api
{
add_header 'Access-Control-Allow-Origin' '*';
proxy_pass http://shop.test/api;
}
后端项目配置跨域
location / {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
}