栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

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

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

样例

域名为http://csdnname
现在要求第一个项目在http://csdnname/下,第二个项目在http://csdnname/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 /html/videoconferencing;
    # 注意这里要加@router,@router的定义在下面
    try_files $uri $uri/ @router;
    index index.html index.htm;
  }
  # 注意要和项目中配置的base一样
  location /manage {
    # 注意是alias不是root
    #alias /html/conferencingmanagement;
    #root模式
    root html;
    # 注意最后是项目中配置的base+index.html不是@router
    try_files $uri $uri/ /manage/index.html;
    index index.html index.htm;
  }
  # 不要漏掉这个
  location @router {
    rewrite ^.*$ /index.html last;
  }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/321103.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号