nginx vue 反代解决跨域问题

张映 发表于 2019-03-01

分类目录: apache/nginx, nodejs/vue/js/jquery

标签:, , ,

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

  1. # cat dsp.conf   //配置  
  2. server  
  3. {  
  4.   
  5.     listen       8080;  
  6.     server_name  10.0.0.237;  
  7.   
  8.     location / {  
  9.         root  /var/www/dsp/dist;  
  10.         index  index.html;  
  11.         try_files $uri $uri/ /index.html;  
  12.     }  
  13.   
  14.     location /api/ {      //接口反代  
  15.         proxy_pass http://10.0.0.30;  
  16.     }  
  17.   
  18.     access_log /var/log/nginx/dsp.access.log;  
  19.     error_log /var/log/nginx/dsp.error.log;  
  20.   
  21. }  
  22.   
  23. # nginx -t   //检测  
  24. nginx: the configuration file /etc/nginx/nginx.conf syntax is ok  
  25. nginx: configuration file /etc/nginx/nginx.conf test is successful  
  26.   
  27. # systemctl reload nginx  //重新加载配置  

 



转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/jsjquery/2069.html