vue nginx 同一端口下两个同级目录处理方法,
例:链接http://xxx.com 访问目录一;http://xxx.com/store 访问目录二;
方法解析:
1、先定义变量并将后面 上级目录(相对主目录的上级)/ 根目录 主目录赋值给$root 变量;
2、用正则表单试判断url访问的是否为目录二,如果是则 上级目录(相对主目录的上级) 赋值给$root变量
3、 location /store 做vue 跳转处理,注意必须加上 /目录二/index.html
#端口号
listen 80;
#域名
server_name xxx.com;
#定义变量 此为目录一
set $root data/web;
#判断url中是否存在 /store 目录
if ( $request_uri ~* ^/store ) {
#定义变量 此为目录二 绝对路径:/mnt/data/store
set $root data;
}
#组合拼接引用目录
root /mnt/$root;
index index.php index.html index.htm;
location ~ \.(htm|html)$ {
add_header Cache-Control no-store;
expires -1;
}
location / {
#根目录跳转
try_files $uri $uri/ /index.html =404;
}
# 此为目录二 必须对应上面的目录二
location /store {
#目录跳转 注意 这里必须为 /目录二/index.html;
try_files $uri $uri/ /store/index.html;
}
error_page 404 /index.html;
location ~* ^.+\.(jpg|jpeg|gif|png|bmp)$ {
access_log off;
expires 30d; break;
}