nginx部署多个history模式的vue项目

487 阅读1分钟

1、修改路由配置

const createRouter = () => new Router({
  mode: 'history',
  // 和子域名需要保持一致
  base: '/manage',
  routes
})

2、修改配置文件

cli2构建的项目

module.exports = {
  // 注意要和要求的子域名一致
  assetsPublicPath: '/manage/'}

cli3构建的项目

module.exports = {
  // 注意要和要求的子域名一致
  publicPath: '/manage/'
}

3、nginx配置

server {
  listen 8080;

  server_name localhost;

  # 注意要和项目中配置的base一样
  location /view{
    alias /home/ubuntu/vue/conferencingmanagement;
    try_files $uri $uri/ /manage/index.html;
    index index.html index.htm;
  }

  # 注意要和项目中配置的base一样
  location /manager{
    alias /home/ubuntu/vue/conferencingmanagement;
    try_files $uri $uri/ /manage/index.html;
    index index.html index.htm;
  }
}