本地这里有两个端口:
8080:前端页面
80:后端接口
在nginx配置
listen 8888;
server_name 127.0.0.1;
location / {
root html;
proxy_pass http://127.0.0.1:8080;
# try_files $uri $uri/ /index.php$is_args$args;
index index.html index.htm;
}
location ~ /apis/ { #添加访问目录为/apis的代理配置
rewrite ^/apis/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:80;
}
rewrite ^/apis/(.*)$ /$1 break;这句绝对不能少。
原本的接口为http://127.0.0.1:80
改为http://127.0.0.1:8888/apis即可
这样就不会跨域了