Nginx开启Brotli

#先下载brotli
git clone https://github.com/google/ngx_brotli.git
#进入目录
cd ngx_brotli
#更新brotli
git clone https://github.com/google/brotli.git
git submodule update --init
#进入nginx源码目录
cd xxx/nginx
#生成makefile,注意根据自己使用的模块添加
./configure  ...  --add-module=../ngx_brotli
#编译nginx
make && make install
如果编译不出错的情况下,输入nginx -V就可以看到ngx_brotli模块了

brotli on; #启用
brotli_comp_level 6; #压缩等级,默认6,最高11,太高的压缩水平可能需要更多的CPU
brotli_buffers 16 8k; #请求缓冲区的数量和大小
brotli_min_length 1k; #指定压缩数据的最小长度,只有大于或等于最小长度才会对其压缩。这里指定1k
brotli_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml text/html application/json image/svg application/font-woff application/vnd.ms-fontobject application/vnd.apple.mpegurl image/x-icon image/jpeg image/gif image/png image/bmp; #指定允许进行压缩类型
brotli_static always; #是否允许查找预处理好的、以.br结尾的压缩文件,可选值为on、off、always
brotli_window 512k; #窗口值,默认值为512k

# .unityweb类型文件添加gzip压缩头
    # 如果Unity中未开启gzip,关闭该配置
    location ~ .+\.unityweb$ {
        add_header Content-Encoding gzip;
    }
 
    # wasm使用gzip压缩,设置MIME type为application/wasm wasm
    location ~ .+\.wasm$ {
        add_header Content-Encoding gzip;
        types {
          application/wasm wasm;
        }

./configure: error: C compiler cc is not found
yum install gcc gcc-c++ -y

Centos8 repo 'AppStream'下载元数据失败
修改 /etc/yum.repos.d/CentOS-Linux-Base.repo,CentOS-Linux-AppStream.repo,CentOS-Linux-Extras.repo
注释mirrorlist,把baseurl取消注释并修改为阿里云镜像地址
baseurl=https://mirrors.aliyun.com/centos/$releasever-stream/BaseOS/$basearch/os/
baseurl=https://mirrors.aliyun.com/centos/$releasever-stream/AppStream/$basearch/os/
baseurl=https://mirrors.aliyun.com/centos/$releasever-stream/extras/$basearch/os/
# 清除所有缓存文件
yum clean all
# 制作元数据缓存
yum makecache

cd nginx-1.*.*
./configure --with-compat --add-dynamic-module=/usr/src/ngx_brotli

./configure: error: the HTTP rewrite module requires the PCRE library.
yum -y install pcre-devel
./configure: error: the HTTP gzip module requires the zlib library.
yum -y install openssl openssl-devel

make modules

load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值