nginx和apache添加brotli算法压缩网站

什么是brotli?

brotliGoogle开发的最新压缩算法,有效减少网站传输数据
具体内容请查看WIKI
https://en.wikipedia.org/wiki/Brotli

安装依赖文件[仅限centos]

yum groupinstall 'Development Tools' -y
yum install cmake -y

编译安装brotli库

wget https://github.com/google/brotli/archive/v1.0.3.tar.gz
tar -zxvf v1.0.3.tar.gz
cd brotli-1.0.3
./configure-cmake
make 
make test 
make install

apache/nginx添加编译参数

 "--enable-brotli"  \
"--with-brotli=/usr/local/lib" \   #apache官方模块,依赖brotli库 

--add-module=../ngx_brotli-master   #添加ngx_brotli模块编译

ngx_brotli模块下载地址
https://github.com/google/ngx_brotli
https://github.com/eustas/ngx_brotli

apache/nginx修改配置文件

http://httpd.apache.org/docs/2.4/mod/mod_brotli.html
apache修改文件 /etc/httpd/conf/extra/httpd-deflate.conf

<IfModule brotli_module> 
 SetOutputFilter BROTLI_COMPRESS;DEFLATE
 SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip no-brotli dont-vary
 BrotliCompressionQuality  6
 BrotliCompressionWindow 18
 AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/css text/xml
 AddOutputFilterByType BROTLI_COMPRESS application/x-javascript application/javascript
 AddOutputFilterByType BROTLI_COMPRESS application/rss+xml
 AddOutputFilterByType BROTLI_COMPRESS application/xml
 AddOutputFilterByType BROTLI_COMPRESS application/json
</IfModule>
#nginx配置文件  
    brotli on;
    brotli_types text/html text/plain text/javascript text/css text/xml text/x-component application/javascript application/x-javascript application/xml application/json application/xhtml+xml application/rss+xml application/atom+xml application/x-font-ttf application/vnd.ms-fontobject image/svg+xml image/x-icon font/opentype;
    brotli_static off;
    brotli_comp_level 6;
    brotli_buffers 8 16k;
    brotli_window 512k;
    brotli_min_length 512;

出错解决办法

nginxerror while loading shared libraries: libbrotlienc.so.1: cannot open shared object file: No such file or directory
可行的解决方案之一,是把对应的库文件做软链接:

# 64 位系统  
 ln -s /usr/local/lib/libbrotlienc.so.1 /lib64 
 ln -s /usr/local/lib/libbrotlicommon.so.1  /lib64

# 32 位系统  
ln -s /usr/local/lib/libbrotlienc.so.1 /lib 
ln -s /usr/local/lib/libbrotlicommon.so.1  /lib

重载nginx,若无报错,即问题解决
nginx -s reload

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
This is a shared library for Android, iOS, OSX, Windows, Linux and webGL to decompress 7z (7zip) files and to compress/decompress zip/gzip (.zip/.gz), LZ4 (.lz4), brotli (.br), fastLZ files and buffers. ZIP plugin: iOS/tvOS compilation may require to add the -lz linking flag at Build Settings-> Linking- > Other Linker flags on xcode. webGL for flz,lzma & lz4 supports buffers compression/decompression only. Brotli supports buffer decompression. webGL for zip supports all functions except those that require file system operations. 7ZIP section: The library serves the scope to have fast decompression of 7z files and compress/decompress lzma files and buffers. - The library does 7z decompression and not 7z compression. Compression of lzma alone files is supported. Passwords are not supported. - It is about 2.5x times faster then using a c# implementation for 7z decompression. - You can extract a single file out of the 7z archive. - If you intend to decompress large files it would be better to use the largeFiles flag.(consumes less ram) - You can extract the contents of the 7z file keeping its folder structure. - Ability to get the filenames and file sizes of files in a 7z archive. - get progress of extraction when the 7zip archive has multiple files. - get byte level progress of 7z decompression (single or multiple files). - get byte level progress of lzma compression/decompression. - Ability to encode/decode to/from .lzma alone format. - Ability to decode a specific file in a 7z archive to a byte buffer. - Ability to decode/encode a byte buffer to/from the lzma alone format. - Ability to cancel the decompression when the 7z archive has multiple entries.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值