有需要服务器方面的需求和咨询,可以联系博主 QQ 7271895
文章目录[隐藏]
- 什么是brotli?
- 安装依赖文件[仅限centos]
- 编译安装brotli库
- apache/nginx添加编译参数
- apache/nginx修改配置文件
- 出错解决办法
什么是brotli?
brotli是Google开发的最新压缩算法,有效减少网站传输数据
具体内容请查看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;
出错解决办法
nginx: error 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
如果有不懂的、欢迎加入我们学派吧。一起学习交流。右上角站长群