Nginx同域名下配置多项目

webpack.config.js

build: {
    index: path.resolve(__dirname, '../dist/index.html'),
    // Paths
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/admin/',
    productionSourceMap: true,
    devtool: '#source-map',
    productionGzip: true,
    productionGzipExtensions: ['js', 'css'],
    bundleAnalyzerReport: process.env.npm_config_report
  }

把 assetsPublicPath修改为你在nginx配置的路径。

router.js

//base要和上面配置的assetsPublicPath配置的一样
 mode:'history',
 base: '/admin/',

配置nginx:

keepalive_timeout  65;
gzip  on;//开启Gzip压缩
gzip_disable 'msie6'; #不使用gzip IE6
gzip_min_length 100k; #gzip压缩最小文件大小,超出进行压缩(自行调节)
gzip_buffers 4 16k; #buffer 不用修改
gzip_comp_level 3; #压缩级别:1-10,数字越大压缩的越好,时间也越长
server {
    listen 80;
    server_name www.xxx.cn;//配置你的域名
    location /{//配置默认的项目
         root /data/www/web;
         try_files $uri $uri/ /index.html;
         index index.html index.htm;
         #proxy_pass http://127.0.0.1:8080;
     }
     location ^~/admin{//配置 域名/admin 对应的项目
         alias /data/www/admin/;//别名 配置项目文件路径
         try_files $uri $uri/ /index.html;
         index index.html index.htm;
         if (!-e $request_filename) {//防止二级路由下页面reload空白页面
             rewrite ^/(.*) /admin/index.html last;
             break;
         }
         #proxy_pass http://127.0.0.1:8080;
     }
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!