多个history模式vue项目的nginx配置

样例

域名为http://hostname
现在要求第一个项目在http://hostname/下,第二个项目在http://hostname/manage/

一、第一个项目

1. 修改路由配置

const createRouter = () => new Router({
  mode: 'history',
  routes
})

2. 修改publicPath(vue.config.js

module.exports = {
  // 去掉也可以
  publicPath: '/'
}

二、第二个项目

1. 修改路由配置

const createRouter = () => new Router({
  mode: 'history',
  // 注意要和要求的子域名一致
  base: '/manage',
  routes
})

2. 修改publicPath(vue.config.js)

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

三、nginx配置

server {
  listen 80;
  listen [::]:80;

  server_name localhost;

  location / {
    # 注意是root不是alias
    root /home/ubuntu/vue/videoconferencing;
    # 注意这里要加@router,@router的定义在下面
    try_files $uri $uri/ @router;
    index index.html index.htm;
  }
  # 注意要和项目中配置的base一样
  location /manage {
    # 注意是alias不是root
    alias /home/ubuntu/vue/conferencingmanagement;
    # 注意最后是项目中配置的base+index.html不是@router
    try_files $uri $uri/ /manage/index.html;
    index index.html index.htm;
  }
  # 不要漏掉这个
  location @router {
    rewrite ^.*$ /index.html last;
  }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容