nginx-http-concat静态资源文件合并

模块介绍

nginx-http-concat 模块由淘宝开发,目前已经包含在tengine中,并且淘宝已经在使用这个nginx模块。不过它暂时没有包含在nginx中。这个模块类似于apache中的modconcat。如果需要使用它,需要使用两个"?"问号.

来个范例:

http://example.com/??style1.css,style2.css,foo/style3.css

以上将原先3个请求合并为1个请求

如果你担心文件被用户的浏览器缓存而没有及时更新,你依旧可以带上一个版本号的参数,如下:

http://example.com/??style1.css,style2.css,foo/style3.css?v=102234

1. 安装 nginx-http-concat

# cd /usr/local/src/
# wget http://nginx.org/download/nginx-1.4.2.tar.gz
# wget https://github.com/alibaba/nginx-http-concat/archive/master.zip -O nginx-http-concat-master.zip
# unzip nginx-http-concat-master.zip
# tar -xzvf nginx-1.4.2.tar.gz
# cd nginx-1.4.2
# ./configure --prefix=/usr/local/nginx-1.4.2 --with-http_stub_status_module \
--add-module=../nginx-http-concat-master
# make
# make install

2. 指令说明, 

    请参考 github中的模块说明,>>>这里

3. 配置nignx 

server {
 
    listen       80;
    server_name  www.example.com;
 
    root /data/site/www.example.com;
    location /static/ {
        concat on;
        concat_max_files 20;
        concat_unique off;
    }
}

4. 验证模块安装成功

   通过访问 http://example.com/??style1.css,style2.css,foo/style3.css , 可以返回的内容包含style1.css, style2.css, style3.css 的内容, 验证成功.


5. 结束语

    使用nginx-http-concat 可以通过减少web请求在一定程度上减少web 服务器的压力, 但目前nginx-http-concat  和proxy_pass 还无法同时使用.  看到网上提到google的pagespeed模块, 还没有使用. 



转载于:https://my.oschina.net/conanxke/blog/519615

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值