在nginx中,指定路径解析至不同vue项目,需求如下:
比如访问 http://www.xxxxx.com 时,解析至pc项目;
如果访问 http://www.xxxxx.com/mc 时,解析至mc项目;
实现方案如下:
首先需要在mc的vue项目中修改vue.config.js配置文件,增加如下代码:
module.exports = {
publicPath: '/mc/' #增加此行
}
配置完成并重新打包vue项目后,再修改Nginx配置如下:
server {
location /mc {
alias /usr/share/nginx/mc/dist;
index index.html;
try_files $uri $uri/ /mc/index.html;
}
location / {
root /usr/share/nginx/pc/dist;
#通过如下动态解析
try_files $uri $uri/ @router;
index index.html;
}
#通过如下动态解析
location @router {
rewrite ^.*$ /index.html last;
}
}
Nginx配置修改完成并重启后,此时http://www.xxxxx.com/mc已经能够正常解析mc项目了!