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

本文详细介绍了如何配置Vue项目以适应不同的子域名,包括修改路由配置和publicPath,确保第一个项目在'http://csdnname/'下运行,而第二个项目在'http://csdnname/manage/'下。同时,提供了相应的Nginx配置示例,以实现正确的路径重定向和文件查找。通过这些步骤,可以成功地部署和管理多个Vue项目。
摘要由CSDN通过智能技术生成

样例

域名为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;
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值