多個(gè)history模式vue項(xiàng)目的nginx配置

樣例

域名為http://hostname
現(xiàn)在要求第一個(gè)項(xiàng)目在http://hostname/下,第二個(gè)項(xiàng)目在http://hostname/manage/

一、第一個(gè)項(xiàng)目

1. 修改路由配置

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

2. 修改publicPath(vue.config.js

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

二、第二個(gè)項(xiàng)目

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;
  }
  # 注意要和項(xiàng)目中配置的base一樣
  location /manage {
    # 注意是alias不是root
    alias /home/ubuntu/vue/conferencingmanagement;
    # 注意最后是項(xiàng)目中配置的base+index.html不是@router
    try_files $uri $uri/ /manage/index.html;
    index index.html index.htm;
  }
  # 不要漏掉這個(gè)
  location @router {
    rewrite ^.*$ /index.html last;
  }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容