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

要求:在同一个域名下nginx配置多个*(history模式)vue项目

例如:域名为 https://ceshi.com
配置两个项目访问路径:1.https://ceshi.com/main 2.https://ceshi.com/activity

vue项目中配置:

  1. 修改路由配置
const createRouter = () => new Router({
 mode: 'history',
 // 注意要和要求的子域名一致
 base: '/one',
 routes
})
  1. 修改publicPath(vue.config.js)
module.exports = {
 // 注意要和要求的子域名一致
 publicPath: '/one/'
}

nginx中配置:

  1. 主域名配置
  	listen 80;
    server_name a.yuming.cn;
    root /test/myFileDir/;
  1. 子配置
  # 注意要和项目中配置的base一样 [域名+/one]
    location /one{
      alias /test/myFileDir/one;
      #vue中配置的 base+/index.html
      try_files $uri $uri/ /one/index.html;
      # index index.html; #这一行默认要不要都可以,看你自己的文件名决定
    }
    
    #第二个项目访问路径  [域名+/two]
    location /two {
      alias /test/myFileDir/two;
      try_files $uri $uri/ /two/index.html;
    }
    
    #第三个....  [域名+/three]
	 location /three{
      alias /test/myFileDir/three;
      try_files $uri $uri/ /three/index.html;
    }

服务器中文件目录:

对应nginx中配置的alias项:/test/myFileDir/one/test/myFileDir/two

以此类推 可以添加任意多个vue history路由模式项目

参考文档:https://www.jianshu.com/p/c23abfadb07f

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ywh22122

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值