前言:

nginx-http-concat模块是由淘宝网开发的,现在淘宝网合并js和css正是用这个模块,如链接http://a.tbcdn.cn/??s/kissy/1.2.0/kissy-min.js,p/global/1.0/global-min.js,p/fp/2012/core.js,p/fp/2012/fp/module.js,p/fp/2012/fp/util.js,p/fp/2012/fp/directpromo.js?t=2012080620120924.js就是合并了kissy-min.js、global-min.js、core.js、module.js、util.js,directpromo.js等js文件。

环境:

Ubuntu 15.04 64位

步骤:

一、环境准备

安装Nginx之前要先准备好Ubuntu 15的环境,安装好Ubuntu系统之后,还需要安装以下组件:

1、apt-get install openssh-server

Windows用XShell连接,Mac 用自带的Terminal连接

2、sudo apt-get install libssl-dev

3、sudo apt-get install build-essential

编译Nginx和Nginx concat用到

4、sudo apt-get install vim

Linux下强大的编辑器

5、sudo apt-get install git

安装Git用于获取Nginx concat包

6、sudo apt-get install libpcre3 libpcre3-dev

安装Perl库,编译Nginx用到

7、sudo apt-get install curl libcurl3 libcurl3-dev php5-curl

测试Nginx页面

二、安装Nginx

1、下载Nginx

http://nginx.org/download/

mkdir /usr/local/Nginx
cd /usr/local/Nginx
wget http://nginx.org/download/nginx-1.9.9.tar.gz
tar zxvf nginx-1.9..tar.gz

2、下载nginx-http-concat

git clone https://github.com/idefav/nginx-http-concat
mv nginx-http-concat /usr/local/src

三、编译

cd ./nginx-1.9.
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --add-module=/usr/local/src/nginx-http-concat
make && make install

四、配置

打开配置文件

vim /usr/local/nginx/conf/nginx.conf

1、CSS

location /static/css/ {
concat on;
concat_types text/css;
concat_max_files ;
}

2、JS

location /static/js/ {
concat on;
concat_types application/javascript;
concat_max_files 30;
}

3、混合

location /static/all/ {
concat on;
concat_types text/css application/javascript;
concat_max_files ;
concat_unique off;
}

五、启动Nginx

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

六、测试

curl http://localhost/static/??jquery.js,jquery.corner.js

七、开启Gzip

配置Gzip
gzip  on;
gzip_min_length 1k;
gzip_buffers 16k;
gzip_disable "MSIE [1-6]\.";
gzip_vary off;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/javascript;
gzip_comp_level ;

重启Nginx

/usr/local/nginx/sbin/nginx -s reload

  测试

/usr/local/nginx# curl -I -H "Accept-Encoding: gzip, deflate"  http://192.168.19.128/static/??jquery.js,jquery.corner.js

  

利用nginx concat模块合并js css的更多相关文章

  1. 转:利用node压缩、合并js,css,图片

    1.安装nodejs http://nodejs.org/ 2.安装各自的node package js我用的是UglifyJS github地址:https://github.com/mishoo/ ...

  2. Grunt的配置及使用(压缩合并js/css)

    Grunt的配置及使用(压缩合并js/css) 安装 前提是你已经安装了nodejs和npm. 你能够在 nodejs.org 下载安装包安装.也能够通过包管理器(比方在 Mac 上用 homebre ...

  3. Tengine的concat模块与js、css合并

    首先,先走出一个误区 ,下面是tengine-cn邮件列表里的一篇邮件原文:“看了这个例子就了解了,这个所谓的合并请求只是把所有的CSS或JAVASCRIPT请求合并,必须是同一个文件类型的.我开始想 ...

  4. 前端构建工具 Gulp 压缩合并JS/CSS 并添加版本号、ES6转ES5

    Gulp 基于 Node.js 的前端构建工具,可以实现前端代码的编译(sass.less).压缩合并(JS.CSS).测试:图片的压缩:已经添加 JS 和 CSS 版本号,防止浏览器缓存. 1. 安 ...

  5. Web性能优化之动态合并JS/CSS文件并缓存客户端

    来源:微信公众号CodeL 在Web开发过程中,会产生很多的js/css文件,传统的引用外部文件的方式会产生多次的http请求,从而加重服务器负担且网页加载缓慢,如何在一次请求中将多个文件一次加载出来 ...

  6. maven 压缩、合并 js, css

    转载自:http://blog.csdn.net/fangxing80/article/details/17639607 我们知道在 Web 应用开发中为了提高客户端响应速度,需要将页面使用的资源最小 ...

  7. nginx concat模块配置 页面返回400 bad request

    在1.4.x版本的nginx没有发现这个问题,但是在1.5.x版本就遇到了这个问题 由于Nginx在新版本中,使用了标准的 MIME-Type:application/javascript.而在ngi ...

  8. nginx js、css多个请求合并为一个请求(concat模块)

    模块介绍 mod_concat模块由淘宝开发,目前已经包含在tengine中,并且淘宝已经在使用这个nginx模块.不过塔暂时没有包含在nginx中.这个模块类似于apache中的modconcat. ...

  9. 引用:使用grunt 压缩 合并js、css文件

    引用:https://www.jianshu.com/p/08c7babdec65 压缩 js 文件 1.创建一个目录 名为grunt   目录.png 2.在grunt目录下创建一个 src目录,存 ...

随机推荐

  1. RadioGroup

    获取选中的Text radioGroup1.Properties.Items[radioGroup1.SelectedIndex].Description

  2. cgLib生成动态代理

    package com.stono.cglib; import java.lang.reflect.Method; import net.sf.cglib.proxy.Enhancer; import ...

  3. line-height系列——定义和工作原理总结

    一.line-height的定义和工作原理总结 line-height的属性值: normal    默认  设置合理的行间距. number  设置数字,此数字会与当前的字体尺寸相乘来设置行间距li ...

  4. PariticalFilter在MFC上的运行,源代码公开

    由于项目需要,进行过一段时间的 PariticalFilter 研究.主要的工作就是将网络上的Console代码和Mfc融合在一起,并且添加了Mfc端的控制功能.       程序还有不完善的地方,现 ...

  5. Jquery右击显示菜单事件,运用smartMenu插件。

    基本格式: 1.引用jquery.smartMenu插件.css样式: <script src="gongju/jquery-1.11.2.min.js" type=&quo ...

  6. Node v0.12.5 稳定版发布

    Node v0.12.5 稳定版发布了,该版本改进记录主要包括: openssl: upgrade to 1.0.1o (Addressing multiple CVEs) npm: upgrade ...

  7. Yii框架中的form表单

    <?php//引入命名空间use yii\helpers\Html;?><?php //表单:Html::beginForm(提交地址,提交方法,属性数组);?><?=H ...

  8. GIS制图课程前言

    一直以来都想写一本关于电子地图制图的工具书,把过去所遇到的关于电子地图制图的种种方法.技巧和问题进行总结和归纳,传播电子地图制图的思路和心得. 从2010年开始,陆陆续续在华南地区开展了多场的电子地图 ...

  9. 原生JS 购物车及购物页面的cookie使用

    ////////////////////////////////////购物页面 <!DOCTYPE html><html lang="en"><he ...

  10. 在Ubuntu12.0至14.04版本之间用Apache搭建网站运行环境

    为了顺利安装各种软件,先更新下系统. apt-get update 安装Apache服务 apt-get install apache2 -y 安装php apt-get install php5 - ...