vue nginx配置默认路径,nginx默认配置

9 篇文章 0 订阅
1 篇文章 0 订阅

我们开发一个系统的2.0版本,之前的版本是纯静态页面,比如登录是:login.html,列表页:list.html。

我们2.0版本是用vue的单页面实现的,路由用的vue-router,要求是如果访问我们之前的某个页面的话,要直接跳转到我们现在的登录页面。

因为我们公司所有外网访问的都有一个跳板机,跳板机再指向目标机器,目标机器上配置相关路径,因为目标机器的路径配置的是带前缀的,用vue官网的那个方式不可用。

后来发现,vue官网配置的那个方法主要是为了,当页面404的时候访问当前的index.html,所以我们根据要求修改了一下目标机器的nginx,配置如下:

 location ~ ^/web/asset/clerk/(.*)$ {
        #try_files $uri $uri/ /data/test/project/front/$1/index.html;
        add_header Cache-Control "no-store";
        alias /data/test/project/front/clerk/$1;
        error_page 404 /web/asset/clerk/index.html;
        gzip on;
        gzip_types text/plain  application/x-javascript text/css text/javascript image/gif image/png image/jpg image/*;
    }


    location /web/asset/clerk/index.html {
        #try_files $uri $uri/ /data/test/project/front/$1/index.html;
        add_header Cache-Control "no-store";
        alias /data/test/project/front/clerk/index.html;
        gzip on;
        gzip_types text/plain  application/x-javascript text/css text/javascript image/gif image/png image/jpg image/*;

    }

这样配置后,当访问:localhost:/web/asset/clerk/login.html的时候,发现页面没找到,就会自动跳转到localhost:/web/asset/clerk/index.html,这样就实现了我司的要求,保证了用户访问之前的页面能跳转到新系统的登录页面。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值