本地跨域配置实用的是proxy,本地测试跨域没有问题,数据能正常接受,后台能console
"/api": {
"target": "http://132.232.22.140:8889/api",
"changeOrigin": true,
"pathRewrite": { "^/api" : "" }
}
部署到服务器后,nginx配置
server {
listen 8000;
# server_name www.alatu..xyz;
root /home/myftp/dist;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location /api {
rewrite ^.+api/?(.*)$ /$1 break;
include uwsgi_params;
proxy_pass http://localhost:8889;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 20M;
keepalive_timeout 10;
}
线上测试收不到数据,后台也没有console啊,有没有前辈帮忙看看,不甚感激!
结案了,原来最大的问题是我的后台没写对,url写错了
8000前端端口,8889后台端口,这样写就跨域成功了