前后端打包略~

一.前端应用配置

  1. env.production的配置信息
    VUE_APP_BASE_API = ‘/prod-api’
# 页面标题
VUE_APP_TITLE = XXXX

# 生产环境配置
ENV = 'production'

# 生产环境
VUE_APP_BASE_API = '/prod-api'
  1. vue.config.js中后端地址配置,如果前后端在同一台主机上,那么配置如下
    target: http://localhost:8080,

二.Nginx配置

注意:location /prod-api/要与VUE_APP_BASE_API = '/prod-api’保持一致

server {
	listen       8081;
	server_name  localhost;

	location / {
		root /home/app/dist;
		try_files $uri $uri/ /index.html;
		index  index.html index.htm;
	}
	
	location /prod-api/{
		proxy_set_header Host $http_host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header REMOTE-HOST $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_pass http://localhost:8080/;
	}

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

访问地址:http://ip:8081/login
接口地址:http://ip:8081/prod-api/xxx

Logo

快速构建 Web 应用程序

更多推荐