centos7.2 x86_64
阿里开源的concat模块,用于减少网站访问中js和css的请求,以减轻服务器压力;该技术即将css、js等静态资源合并为一个或几个资源,配合缓存可大大节省网络传输时间,加快网页加载速度。
1,安装concat模块需编译安装nginx:
yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel pcre pcre-devel git
mkdir -p /var/web/
useradd web
mkdir -p /var/web/
chown web.web /var/web/
cd /var/web/
git clone https://github.com/alibaba/nginx-http-concat.git
wget http://nginx.org/download/nginx-1.12.1.tar.gz
tar zxvf nginx-1.12.1.tar.gz
cd nginx-1.12.1
./configure --prefix=/var/web/nginx --sbin-path=/usr/sbin/nginx --user=web --group=web --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=/var/web/nginx-http-concat
make
make install
2,concat模块使用方法:
#该段代码意味着网站根目录下/static/目录里的css和js才可以合并
location /static/ {
concat on;
concat_max_files 20;
concat_unique off;
concat_types text/css text/html application/javascript;
}
https://localhost/static/??/pc/style/loading.min.css,pc/js/aboutus.min.js,global/js/stats.js
该链接能看到对应js和css的内容即为配置concat成功可用