iview-admin项目修改部署到nginx后可以成功运行,但当访问后台接口的时候就出现跨域问题。
由于后端使用的端口和前端不一致导致的问题。
对nginx.conf进行配置
server {
listen 8080;
server_name ****;
location / {
root /home/wwwroot/dist;
index index.html;
}
location /api/ {
proxy_pass http://xxxx:8000; #就是把接口为 /api/xxx的功能转发给后端就可以解决跨域问题
}
}