Nginx添加开启ngx_brotli模块
- 环境介绍
- 查看已有模块
/usr/local/nginx/sbin/nginx -V
- 检查是否有git命令
git
- 安装git
yum -y install git
- 下载 ngx_brotli
mkdir /usr/local/ngx_module
cd /usr/local/ngx_module/
git clone https://github.com/google/ngx_brotli.git
cd ngx_brotli/
git submodule update --init
- 重新编译Nginx
不要执行安装(make install)
cd nginx-1.18.0/
/usr/local/nginx/sbin/nginx -V
./configure --with-http_gzip_static_module --add-module=/usr/local/ngx_module/ngx_brotli
make
- 备份nginx启动程序并且复制新生成obj目录的nginx启动文件
/usr/local/nginx/sbin/nginx -s stop
cp /usr/local/nginx/sbin/nginx nginx.bak
cp objs/nginx /usr/local/nginx/sbin/nginx
- 在/etc/nginx/nginx.conf开启Brotli:
http {
brotli on;
brotli_comp_level 6;
brotli_buffers 16 8k;
brotli_min_length 20;
brotli_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml;
}
如图:
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -V
/usr/local/nginx/sbin/nginx
至此结束