找到nginx多网站配置文件:类似 nginx/sites-available/www.baidu.com
server {
listen 80;
index index.html index.htm index.nginx-debian.html;
server_name www.baidu.com;
location / {
root /mnt/www/www.baidu.com;
try_files $uri $uri/ /index.html;
}
}参考页面:https://router.vuejs.org/zh-cn/essentials/history-mode.html
cnpm run build 文件过大
打包生成文件:

浏览器访问效果:

Nginx开启gzip
找到nginx.config。关于gzip压缩代码:
http {gzip on; #开启或关闭gzip on off
gzip_disable "msie6"; #不使用gzip IE6
gzip_min_length 100k; #gzip压缩最小文件大小,超出进行压缩(自行调节)
gzip_buffers 4 16k; #buffer 不用修改
gzip_comp_level 3; #压缩级别:1-10,数字越大压缩的越好,时间也越长
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; # 压缩文件类型
gzip_vary off; #跟Squid等缓存服务有关,on的话会在Header里增加 "Vary: Accept-Encoding"
}配置完重启Nginx
浏览器访问效果:

上面为数据流接收大小,下面为解压后实际大小。
识别gzip与非gzip请求
gzip请求:

非gzip请求:

gzip与非gzip在响应头中区别就是Content-Encoding是否表明是gzip压缩格式。
而上面通过接收数据与实际数据大小相比也能明显看出差异
webpack gzip
vue项目中config/index.js
productionGzip: true, //是否开启gizp压缩
productionGzipExtensions: ['js', 'css'],开启后cnpm run build会生成*.gz文件。
像这样:

上传到服务器,测试查看接受文件大小。










