如果管理页面是以根目录形式访问,那这里就不需要配置了,直接编译打包部署到nginx就可以了,但要加项目名的形式就需要部分修改了
假设管理页面项目名:admin 后端项目名:pro-api
修改文件.env.production
VUE_APP_BASE_API = '//localhost:8080/pro-api'
修改vue.config.js
publicPath: process.env.NODE_ENV === "production" ? "/admin/" : "/",
修改路由src/router/index.js
export default new Router({
base: '/admin',
mode: 'history',
scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes
})
修改src/layout/components/Navbar.vue
this.$store.dispatch('LogOut').then(() => {
location.href = this.$router.options.base;
})
打包部署到nginx
nginx配置
location /admin/ {
root D:\Project\demo\dist;
index index.html index.htm;
}
location /pro-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/;
}
|