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

我们开发一个系统的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,这样就实现了我司的要求,保证了用户访问之前的页面能跳转到新系统的登录页面。

猜你喜欢

转载自blog.csdn.net/lizhen_software/article/details/80402450