页面压缩:自动去除html文件中非必要的字符(空白、注释等)

一、安装trrim模块:需要使用到淘宝tengine中trim模块

1,下载tengine:http://tengine.taobao.org/download.html
nginx openresty配置页面压缩
2,解压压缩包,找到modules下的ngx_http_trim_filter_module文件夹,复制此模块文件,放在项目服务器的 usr/loacl/src文件下:
nginx openresty配置页面压缩

二、编译openresty:

1,命令行进到nginx目录 /usr/local/openresty/nginx/sbin,查看当前openresty版本:./nginx -V
nginx openresty配置页面压缩
2,下载openresty1.15.8.3(版本号要与当前使用的openresty版本一致),并将其放在项目服务器的 usr/loacl/src文件下:
nginx openresty配置页面压缩
3,命令行cd到openresty目录:cd /usr/local/src/openresty-1.15.8.3
4,命令执行 ./configure --add-module=/usr/local/src/ngx_http_trim_filter_module
5,然后 make 即可 (不要make install),编译成功。

三、将编译好的nginx配置文件替换项目中的nginx配置文件:

1,关闭nginx:./nginx -s stop (进到/usr/local/openresty/nginx/sbin目录执行)
2,将/usr/local/src/openresty-1.15.8.3/build/nginx-1.15.8/objs下的nginx配置文件复制,到/usr/local/openresty/nginx/sbin即可,记得sbin文件夹下面的nginx备份一下。
3,最后启动nginx (./nginx),查看版本(./nginx -V),可以看到此模块已安装:
nginx openresty配置页面压缩
4,将此配置放在缓存配置中 :
trim on;
trim_js on;
trim_css on;

相关文章: