微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

nginx 的提升多个小文件访问的性能模块

阿里开源的第三方模块下载地址:https://github.com/alibaba/nginx-http-concat

下载模块

 git clone  https://github.com/alibaba/Nginx-http-concat.git

 编译进Nginx

cd Nginx-1.15.9/
使用--add-module=参数指定第三方模块路径
 ./configure --prefix=/data/web --sbin-path=/usr/bin --user=Nginx --group=Nginx --with-http_stub_status_module --with-http_auth_request_module --add-module=/root/Nginx-http-concat
make 主
cp ~/Nginx-1.15.9/objs/Nginx /usr/bin/  把可执行文件复制指定目录,备份之前可执行文件

  配置

server {
	server_name concat.com;
	error_log logs/concat_error.log debug;
	concat on;  #是否启用
	root html;
	location /concat {
		concat_max_files 30; # 定义可在给定上下文中连接的最大文件数。请注意给定的URI不能大于平台的页面大小。在Linux上,您可以获得页面大小发布:
		concat_types text/plain text/css text/html;#定义可在给定上下文中连接的MIME类型
		concat_unique on;#定义是否只能连接给定MIME类型的文件,或者是否可合并多类型。例如,如果off 在给定的上下文中设置为then,则可以连接Javascript和CSS文件。请注意,认值为on,意味着只有具有相同MIME类型的文件在给定上下文中连接。所以,如果你有CSS和JS,你不能做这样的事情:为了做到这一点,你必须设置concat_unique off。这适用于您决定通过添加相应的MIME类型来连接的任何其他类型的文件concat_types,
		concat_delimiter ':::'; #定义两个文件间的分隔符。如果配置为concat_delimiter“\ n”,则当访问http://example.com/??1.js,2.js时,将在1.js和2.js之间插入'\ n'。
		concat_ignore_file_error on;#是否忽略404和403。
	}
}  

    网页

[root@python html]# mkdir concat
[root@python html]# cd concat/
[root@python concat]# echo "1.txt" > 1.txt
[root@python concat]# echo "2.txt" > 2.txt
[root@python concat]# echo "2.css" > 2.css
[root@python concat]# echo "1.css" > 1.css

  

测试

[root@python vhast]# curl www.concat.com/concat/??1.css,2.txt,2.css,1.txt
1.css
:::2.txt
:::2.css
:::1.txt
[root@python vhast]# curl www.concat.com/concat/??1.css,2.txt,1.txt
1.css
:::2.txt
:::1.txt
[root@python vhast]# curl www.concat.com/concat/??1.txt,2.txt
1.txt
:::2.txt

  

  

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐