Nginx的Gzip模块

​ Gzip是压缩文件大小用的。首先把一个演示文件jquery-3.3.1.js放在/usr/local/nginx/html下面。使用ll可以看到压缩之前的大小【单位字节— byte】。

1
2
3
4
5
6
7
8
(localhost.localdomain)/usr/local/nginx/html>ll
总用量 288
-rw-r--r--. 1 root root 589 3月 25 20:06 50x.html
-rw-r--r--. 1 root root 131 3月 25 20:04 haha.html
drwxr-xr-x. 2 root root 4096 3月 28 18:29 images
-rw-r--r--. 1 root root 676 3月 25 22:07 index.html
drwxr-xr-x. 2 root root 4096 3月 29 11:23 jquery-3.3.1
-rw-r--r--. 1 root root 271751 3月 29 11:24 jquery-3.3.1.js

fanfgwen

​ 此时想压缩jquery.js的大小就需要修改配置nginx.conf。让gzip功能开放并指定压缩的文件类型,默认是文本文件text/plain。而这时是js类型【application/javascript 】。参考官网https://nginx.org/en/docs/http/ngx_http_gzip_module.html配置。我滴修改如下

1
2
gzip  on;
gzip_types application/javascript text/plain ;

压缩后