nginx_concat_module是淘宝开发的一个nginx的模块,很是有用的模块,安装了此模块,能够让咱们对js,css等文件进行合并,从而减小访问网站的请求数。javascript
一、下载:淘宝下载地址:css
svn co http://code.taobao.org/svn/nginx_concat_module/trunk nginx_concat_modulehtml
二、安装:java
./configure –prefix=/usr/local/nginx –user=www –group=www –with-http_stub_status_module –with-http_ssl_module –with-pcre –add-module=/root/nginx_concat_modulenginx
make && make installapp
咱们要注意的就是–add-module=/root/nginx_concat_module这一段,这里的路径就是你解压concat.tar.gz的nginx_concat_module这个文件夹的路径svn
三、配置:网站
你的须要实现文件合并的网站的配置文件加上spa
concat on;code
如我这个配置:
server {
listen 80;
server_name 192.168.1.100;
root /data/www/test;
index index.html;
location / {
concat on;
}
}
四、使用:
如今咱们在网站目录下放置2个js文件,1.js和2.js
咱们能够经过http://192.168.1.100/??1.js,2.js访问,发现2个JS的文件都在咱们访问的页面里面了;然 后咱们在网站根目录下新建一个目录abc,在目录abc里面放上3.js,而后咱们经过域名访问http://192.168.1.100 /??1.js,2.js,abc/3.js访问,3个js的内容都在咱们访问的页面上了,在这里,你们注意下,咱们展现出来的页面里面内容的顺序是和我 们访问的文件的排序有关的,排在最前面的文件,就如今在最上面,依次排列,排在最后的文件就在最下面显示出来。
五、注意:concat还有一些参数,你们能够根据须要设置:
concat on; #nginx_concat_module模块的开关
concat_max_files 10; #最大合并文件数
concat_unique on; #只容许同类型文件合并
concat_types text/html;#容许合并的文件类型,多个以逗号分隔。如:application/x-javascript, text/css