Nginx资源合并优化模块nginx-http-concat

此模块是nginx的第三方模块nginx-http-concat,此模块可以合并资源,节约带宽和节约请求响应时间

下载地址

git clone git://github.com/alibaba/nginx-http-concat.git

官网解释

https://github.com/alibaba/nginx-http-concat

首先将此模块编译进nginx里

/usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.13.9

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)

built with OpenSSL 1.0.1e-fips 11 Feb 2013

TLS SNI support enabled

configure arguments: --prefix=/usr/local/nginx --add-module=/root/nginx-1.13.9/nginx-http-concat --add-module=/root/nginx-1.13.9/naxsi-0.56rc1/naxsi_src --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_image_filter_module --with-http_slice_module --with-mail --with-threads --with-file-aio --with-stream --with-mail_ssl_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-pcre --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module && make

将新编译的/objs/nginx里的 Nginx放到/usr/local/nginx/sbin里 把旧的nginx备份好

开始编辑conf 目录里的nginx.conf文件

在server字段里添加如下配置文件

location /css/ {
concat on; #开启资源合并
concat_max_files 20; #允许合并的最大资源数目
concat_unique on; #允许合并不同类型资源
concat_ignore_file_error on; #忽略404或403错误
}
location /js/ {
concat on; #开启资源合并
concat_max_files 20; #允许合并的最大资源数目
concat_unique on; #允许合并不同类型资源
concat_ignore_file_error on; #忽略404或403错误
}

编辑完成后检查配置文件 重启

/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

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

打开浏览器查看服务器页面响应速度,会有明显的提升。

至此nginx-http-concat模块编译配置完成

点一杯星巴克

原文地址:https://www.cnblogs.com/qingyuanyuanxi/p/8559181.html