加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

nginx vue 反代解决跨域问题

发布时间:2020-12-13 21:41:34 所属栏目:Nginx 来源:网络整理
导读:前端后数据分离后,跨域问题肯定存在的。解决办法cors,jsonp解决跨域问题,当然服务端要设置信认。也可以设置成同域,这样跨域问题就不存在了。 # cat dsp.conf //配置server{listen 8080;server_name 10.0.0.237;location / {root /var/www/dsp/dist;index

前端后数据分离后,跨域问题肯定存在的。解决办法cors,jsonp解决跨域问题,当然服务端要设置信认。也可以设置成同域,这样跨域问题就不存在了。

# 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  //重新加载配置

 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读