背景:前端用vue开发了aproj、bproj两个项目,各自发布后有dist目录,dist目录分别改为aprojdist和bprojdist目录,两个目录下都是index.html单页面。现在将这两个页面发布在同一个端口。
如:
192.168.0.1/a/
192.168.0.1/b/
vue项目修改:
用vue cli3 3.2版本搭建的项目
修改vue.config.js文件,没有的话新创建一个。添加:
aproj:
// vue.config.js
module.exports = {
// 选项...
baseUrl: "/a/"
};
修改路由,添加 base:"/a/"
import Vue from "vue";
import Router from "vue-router";
Vue.use(Router);
export default new Router({
base: "/a/", //////////
routes: [
{
path: "/",
redirect: "/index"
}
...
]
});
bproj:
// vue.config.js
module.exports = {
// 选项...
baseUrl: "/b/"
};
修改路由,添加 base:"/b/"
import Vue from "vue";
import Router from "vue-router";
Vue.use(Router);
export default new Router({
base: "/b/", //////////
routes: [
{
path: "/",
redirect: "/index"
}
...
]
});
nginx的配置文件:
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
}
#### 主要配置位置
location /a {
root /www;
index index.html;
try_files $uri $uri/ /aprojdist/index.html;
}
location /b {
root /www;
index index.html;
try_files $uri $uri/ /bprojdist/index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
网友评论