前端之家收集整理的这篇文章主要介绍了
nginx vue 反代解决跨域问题,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_
403_0@前端后数据分离后,跨域问题肯定存在的。
解决办法cors,jsonp
解决跨域问题,当然服务端要设置信认。也可以设置成同域,这样跨域问题就不存在了。
@H_
403_0@
# cat dsp.conf //配置
server
{
listen 8080;
server_name 10.0.0.237;
location / {
root /var/www/dsp/dist;
index index.html;
try_files $uri $uri/ /index.html;
}
location /api/ { //接口反代
proxy_pass http://10.0.0.30;
}
access_log /var/log/Nginx/dsp.access.log;
error_log /var/log/Nginx/dsp.error.log;
}
# Nginx -t //检测
Nginx: the configuration file /etc/Nginx/Nginx.conf Syntax is ok
Nginx: configuration file /etc/Nginx/Nginx.conf test is successful
# systemctl reload Nginx //重新加载配置
@H_
403_0@