为Nginx启用Brotli压缩
source link: https://www.bboy.app/2022/02/24/%E4%B8%BANginx%E5%90%AF%E7%94%A8Brotli%E5%8E%8B%E7%BC%A9/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
为Nginx启用Brotli压缩
Brotli算法是谷歌在15年的时候推出的,针对常见的web内容,相比于gzip,Brotli性能更高。
首先查看nginx的编译参数
sbin/nginx -V
之后下载nginx的brotli模块
git clone https://github.com/google/ngx_brotli.git
cd /data/nginx/nginx-src/ngx_brotli && git submodule update --init && cd /data/nginx/nginx-src/nginx-1.20.2
接着开始编译nginx
./configure --prefix=/data/nginx/nginx --with-stream --with-http_ssl_module --with-http_stub_status_module --add-module=/data/nginx/nginx-src/nginx-module-vts --with-http_realip_module --with-http_v2_module --add-module=/data/nginx/nginx-src/ngx_brotli
make
替换老的nginx
cp nginx /data/nginx/nginx/sbin/nginx
配置nginx,在http模块上加入
gzip off;
brotli on;
brotli_comp_level 11;
brotli_static on;
brotli_types *;
之后查看你的网站
如果请求中
content-encoding
头部的值是br,那么就表示配置成功了
欢迎关注我的博客www.bboy.app
Have Fun
欢迎关注我的其它发布渠道
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK