场景:www.xxx.com网站添加子路径,分别指向不同项目,如www.xxx.com/project1 、www.xxx.com/project2
1、项目打包时补充publicPath,指定js和css等资源的路径前缀为project1或者project2
https://www.webpackjs.com/guides/public-path/
2、子项目所在nginx配置location
location /project1/ {
alias html/project1; #编译后代码路径
index index.html index.htm;
}
location /project2/ {
alias html/project2;
index index.html index.htm;
}
3、公网nginx配置location
location /project1/ {
proxy_pass http://127.0.0.1:80/project1/; #访问路径及端口
}
location /project2/ {
proxy_pass http://127.0.0.1:80/project2/; #访问路径及端口
}
location ~* /(project2|project2)/.*\.(gif|jpg|jpeg|bmp|png|js|css)${
proxy_pass http://127.0.0.1:80;#访问路径及端口
}