一、网文示例

部署在非根目录。比如/admin前缀打开的是前端项目。(注:打包后的静态资源也转到 /admin 前缀下,将vue项目配置 publicPath 值改为 /admin)

1
2
3
4
5
6
7
8
9
10
11
12
server {
listen 80;
server_name ***.com;
location /admin {
alias /var/www/html;
try_files $uri $uri/ /admin/index.html;
}
# 其他配置不影响的
location / {
proxy_pass http://***;
}
}

二、本地测试

vue or vuepress 打包时,基本打包路径需要改为 base:'/blog/' or publicPath:'/blog/'

nginx静态文件目录部署路径

1
2
3
4
5
6
location  /blog {
#root html;
alias /usr/local/nginx/html/blog;
# index index.html index.htm;
try_files $uri $uri/ /blog/index.html;
}