【VUE项目部署】How Config Nginx

vue-cli构建的build编译后目录并不一定适合每种项目的情况
承接vue-run-build后续
下面把做的发布配置和nginx配置发下 留个底……
config/index.js

build: {
    env: require('./prod.env'),
    index: path.resolve(__dirname, '../dist/index.html'),
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: './',
    assetsPublicPath: 'http://xxx.xxx.com:xxxx/',
    productionSourceMap: true,
    // Gzip off by default as many popular static hosts such as gzip有需要去nginx里配置
    // Surge or Netlify already gzip all static assets for you.
    // Before setting to `true`, make sure to:
    // npm install --save-dev compression-webpack-plugin
    productionGzip: false,
    productionGzipExtensions: ['js', 'css']
  },

nginx

server {
    listen 端口号;
    server_name 名称;

    client_max_body_size 20m;
    charset utf-8;

    root /home/xxxx/projects/xxx-admin/dist/; 项目打包目录
    index index.html;

    location / {
        try_files $uri $uri/ @rewrites;//都重新指向到首页保证路由不会乱
    }
    location @rewrites {
        rewrite ^(.+)$ /index.html last;//配置指向
    }

}

你可能感兴趣的:(【VUE项目部署】How Config Nginx)