From cae7d431f0a5698af9b56c9eaf0b20ba2d767ef9 Mon Sep 17 00:00:00 2001 From: bing Date: Wed, 9 Feb 2022 20:52:38 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0nginx=20br=E5=8E=8B?= =?UTF-8?q?=E7=BC=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx/brotli/readme.md | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 nginx/brotli/readme.md diff --git a/nginx/brotli/readme.md b/nginx/brotli/readme.md new file mode 100644 index 0000000..6a517ef --- /dev/null +++ b/nginx/brotli/readme.md @@ -0,0 +1,54 @@ +# nginx开启br压缩 + +参考项目[brotli](https://github.com/google/ngx_brotli) + +**br压缩只能在https中开启。** + +## 编译模块 + +下载nginx源码用于编译模块, 不需要编译nginx,源码需要与运行的nginx版本对应。 + +```bash +wget http://nginx.org/download/nginx-1.21.6.tar.gz +tar xf nginx-1.21.6.tar.gz +``` +下载项目源码 + +```bash +git clone https://github.com/google/ngx_brotli.git +``` + +安装依赖包 + +```bash +yum install brotli brotli-devel pcre2-devel +``` + +配置并编译 + +``` +cd nginx-1.21.6 +./configure --with-compat --add-dynamic-module=/home/kun1h/git/ngx_brotli/ +make modules +``` + +编译好的模块在objs目录。 + +## 运行并加载模块 + +使用docker运行nginx + +```bash +sudo docker run --name nginx -p 80:80 -v /data/nginx/modules:/usr/lib/nginx/modules/extend -v /data/nginx/conf.d:/etc/nginx/conf.d -v /data/nginx/html:/var/www/html -v /data/nginx/logs:/var/log/nginx -v /data/nginx/nginx.conf:/etc/nginx/nginx.conf -d nginx:1.21 +``` + +配置nginx.conf。添加以下内容到nginx.conf的顶部 + +```bash +#for modules +load_module modules/extend/ngx_http_brotli_filter_module.so; +load_module modules/extend/ngx_http_brotli_static_module.so; + +``` + +配置必须位于 `event {}` 与 `http {}`之前 \ No newline at end of file