关于vue打包dist部署nginx访问后端服务出现跨域问题

后端访问请求

http://localhost:8888/demoRepair/test/hello

VUE包

进行配置端口改成访问8000

/**
 * demo环境
 */
;(function () {
  window.SITE_CONFIG = {}

  window.SITE_CONFIG['baseUrl'] = 'localhost:8888/demoRepair'// 后台接口

  // cdn地址 = 域名 + 版本号
  // window.SITE_CONFIG['domain'] = 'https://platform-wxmall.oss-cn-beijing.aliyuncs.com/boot/' // 域名
  window.SITE_CONFIG['domain'] = './' // 域名
  window.SITE_CONFIG['version'] = '2006310900'   // 版本号(年月日时分)
  window.SITE_CONFIG['cdnUrl'] = window.SITE_CONFIG.domain + window.SITE_CONFIG.version
})()

Nginx配置

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
	# 这里进行配置访问后端的服务IP:PORT
	upstream demo-repair{
		server 127.0.0.1:8888;
	}

    server {
        listen       8000;
        server_name  localhost;
		# 后端定义的context-path
        location /demoRepair {
            root   html;
            index  index.html index.htm;
			proxy_pass http://demo-repair;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
Logo

前往低代码交流专区

更多推荐