vue 配置二级目录以及nginx多网站配置

  1. 在vue.config.js
    module.exports = {
      publicPath: '/adm/',  // 二级目录
      devServer: {
        open: true,
        port: 8888
      }
    }
  2. router中配置
    const router = new VueRouter({
      mode: 'history',
      // base: process.env.BASE_URL,
      base: '/adm/',  // 二级目录
      routes
    })

     

  3. nginx多网站配置 根据location部署
        server {
            listen       80;
            server_name  localhost;
    
            location / {  //  前台网站  访问 127.0.0.1
                root   dist;  // 根目录下直接放了一个dist前端代码
                index  index.html index.htm;
                try_files $uri $uri/ /index.html; // 刷新空白
            }
    
            location /adm { // 后台网站  访问  127.0.0.1/adm
                alias   adm/dist; // 根目录下adm文件夹下有一个dist前端代码
                index  index.html index.htm;
                try_files $uri $uri/ /index.html;
            }
        }

    注意:
    二级目录下 要使用alias 不能使用root

posted @ 2022-02-22 18:59  Janus2003  阅读(581)  评论(0编辑  收藏  举报