首先這個坑跟nginx關系不大
1. 需要配置vue-router
創(chuàng)建vue路由 這里 需要配置(這里用的createWebHistory,用其它的也可以)
createWebHistory('/folder/') // 給出的網(wǎng)址為 https://xxx.com/folder/
https://router.vuejs.org/zh/api/#createwebhistory
舊版本的vue-router需要配置的是 base
2. 配置 vue 基本路徑
publicPath: '/folder/'
多個vue項目可以把地址區(qū)分開就行
舊版本的自己查一下吧
3. nginx配置
location / {
root html/web;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
# vue沒配置的路徑的這里不需要配置路徑
location /folder{
alias html/folder;
# vue配置好路徑的 匹配路徑
try_files $uri $uri/ /folder/index.html;
}
location /folder2{
alias html/folder2;
# vue配置好路徑的 匹配路徑
try_files $uri $uri/ /folder2/index.html;
}
這就可以跑起來測試了