樣例
域名為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;
}
}