前提,多个项目功能重复,每次开发都需要复制一份代码且需同时维护多个项目。如:后台管理功能中的菜单管理、角色管理等。
项目A地址为http://192.168.1.1:80 对应的管理后台地址为http://192.168.1.1:80/setting
项目B地址为http://192.168.1.1:81 对应的管理后台地址为http://192.168.1.1:81/setting
## 项目A对应的代理
server {
listen 80;
server_name www.aabb.com;
location / {
root /vueA/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /setting {
alias /setting/dist;
index index.html index.htm;
try_files $uri $uri/ /setting/index.html;
}
## 这里是后端服务A
location /api/ {
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://192.168.2.1:8001;
}
}
## 项目B对应的代理
server {
listen 81;
server_name www.aabb.com;
location / {
root /vueB/dist
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /setting {
alias /setting/dist;
index index.html index.htm;
try_files $uri $uri/ /setting/index.html;
}
## 这里是后端服务B
location /api/ {
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://192.168.2.2:8001;
}
}
复制代码
alias /setting/dist;
对应的是抽离出来的后端管理项目打包后的代码。try_files $uri $uri/ /setting/index.html
需要在前面加上/settingvue.config.js
module.exports = {
publicPath: '/setting', // 基本路径
}
复制代码
router.js
const router = new VueRouter({
mode: 'history',
base: '/setting',
routes
})
复制代码
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。