3.1.2:concat 模块(Tengine)
网站中的css、js等文件件都是小文件,单个文件几k甚至几个字节,所以文件的特点是小而多,会造成网站加载时http请求较多,且网络传输时间比较短,甚⾄有时候请求时间比传输时间还长;
当公司网站中的这类小文件很多时,大量的http请求就会造成传输效率低,影响网站站的访问速度和客户端体验,这时合并http请求就非常有必要了;
concat模块就提供了合并文件http请求的功能,这个模块由淘宝开发,功能和apache的mod_concat模块类似。
编译 concat 动态模块
- 安装 lua 和 lua-devel:
[root@node105 ~]# yum install lua lua-devel
- 查看之前的 tengine 编译参数
[root@node105 ~]# nginx -V
Tengine version: Tengine/2.1.2 (nginx/1.6.2)
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/apps/tengine --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-file-aio --with-ipv6
loaded modules:
ngx_core_module (static)
ngx_errlog_module (static)
……
- 重新编译 tengine,将concat和lua编译为动态模块:
[root@node105 ~]# cd /usr/local/src/tengine-2.1.2/
[root@node105 tengine-2.1.2]# ./configure --prefix=/apps/tengine \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-file-aio \
--with-ipv6 \
--with-http_lua_module=shared \
--with-http_concat_module=shared
[root@node105 tengine-2.1.2]# make
- 安装动态模块:
[root@node105 tengine-2.1.2]# make dso_install
关于 make dso_install
的官方说明:
它将会复制动态库文件到你的动态模块目录,或者你也可以手工拷贝动态模块文件(文件是在objs/modules)到你想要加载的目录.
你能够使用dso_tool(在Nginx安装目录的sbin下)这个工具来编译第三方模块.
示例:
./dso_tool --add-module=/home/dso/lua-nginx-module
将会编译ngx_lua模块为动态库,然后安装到默认的模块路径.如果你想要安装到指定位置,那么需要指定–dst选项(更多的选项请使用dso_tool -h查看).
加载 concat 动态模块
- 查看模块文件:
[root@node105 ~]# ll /apps/tengine/modules/
total 2784
-rwxr-xr-x 1 root root 93937 Dec 5 18:04 ngx_http_concat_module.so
-rwxr-xr-x 1 root root 2755475 Dec 5 18:04 ngx_http_lua_module.so
- 编辑配置文件,加载 concat 动态模块:
dso {
load ngx_http_concat_module.so;
load ngx_http_lua_module.so;
}
- 检查配置文件并重载 tengine:
[root@node105 ~]# nginx -t
the configuration file /apps/tengine/conf/nginx.conf syntax is ok
configuration file /apps/tengine/conf/nginx.conf test is successful
[root@node105 ~]# systemctl reload nginx
验证 concat 模块
- 编辑配置文件,加入 concat 模块参数:
location / {
root html;
index index.html index.htm;
concat on;
}
- 检查配置文件并重载 tengine:
[root@node105 ~]# nginx -t
the configuration file /apps/tengine/conf/nginx.conf syntax is ok
configuration file /apps/tengine/conf/nginx.conf test is successful
[root@node105 ~]# systemctl reload nginx
未报错,表示已支持 concat 功能;