Nginx虚拟路径部署
背景:有时候我们需要在一个项目下部署多个子应用模块,让看起来就像是同一个系统一样,比如http://localhost:3000、http://localhost:3000/admin 的形式。
主应用:http://localhost:3000
子应用:http://localhost:3000/admin
1. 极简模式下的nginx配置
server {
listen 3000;
server_name localhost;
location / {
root /var/www/mainApp; ###配置主应用的文件夹
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /admin { ###配置子应用入口
alias /var/www/adminApp; ###配置子应用的文件夹
index index.html index.htm;
try_files $uri $uri/ /admin/index.html;
}
}
2. 改造admin子应用的Angular打包配置
打包命令从 ng build --prod
修改为 ng build --prod --base-href /admin/
作者:想好了再来改名字
声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。