Tengine 动态加载 concat 模块

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 功能;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值