明月发现参考【给Nginx添加谷歌Brotli压缩算法支持】一文给出的方法,在Debian Linux 12.5下就一直编译失败,主要的错误是因为文件缺失,在专门又安装了apt-get install libbrotli-dev
的依赖库后依然会因为文件缺失无法编译完成,就这样一直卡在这里无法解决。
编译报错的文件缺失:
/usr/bin/ld: 找不到 -lbrotlienc: 没有那个文件或目录
/usr/bin/ld: 找不到 -lbrotlicommon: 没有那个文件或目录
感觉比较诡异的地方是:
git clone https://github.com/google/ngx_brotli.git
每当从GitHub获取ngx_brotli
模块源码的时候速度快的有点儿反常,有好几次还出现了网络错误而中断,由此明月判断问题应该是出在GitHub网站连接畅通上了,只到群里好几个站长都反馈编译ngx_brotli
失败,才算是确定GitHub估计是又被国内给阻断了。唉,这就没有办法了,只能等着恢复了。好在有人说GitHub的阻断好像不是永久的,是一种间歇性的有一定的时间段会被阻断,今天中午就试了一下,git clone
获取源码果然流畅完整了很多,赶紧保留全过程给大家分享一下,以供以后参考:
这次git clone命令用的是官方(GitHub - google/ngx_brotli: NGINX module for Brotli compression)给出的参数:
git clone --recurse-submodules -j8 https://github.com/google/ngx_brotli
执行结果:
正克隆到 'ngx_brotli'...
remote: Enumerating objects: 237, done.
remote: Counting objects: 100% (37/37), done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 237 (delta 24), reused 21 (delta 21), pack-reused 200
接收对象中: 100% (237/237), 79.51 KiB | 407.00 KiB/s, 完成.
处理 delta 中: 100% (114/114), 完成.
子模组 'deps/brotli'(https://github.com/google/brotli.git)已对路径 'deps/brotli' 注册
正克隆到 '/root/lnmp2.0/src/ngx_brotli/deps/brotli'...
remote: Enumerating objects: 7553, done.
remote: Counting objects: 100% (1079/1079), done.
remote: Compressing objects: 100% (399/399), done.
remote: Total 7553 (delta 760), reused 826 (delta 665), pack-reused 6474
接收对象中: 100% (7553/7553), 36.59 MiB | 7.82 MiB/s, 完成.
处理 delta 中: 100% (4892/4892), 完成.
子模组路径 'deps/brotli':检出 'ed738e842d2fbdf2d6459e39267a633c4a9b2f5d'
然后执行:
cd ngx_brotli/deps/brotli
mkdir out && cd out
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_CXX_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_INSTALL_PREFIX=./installed ..
cmake --build . --config Release --target brotlienc
输出结果:
-- The C compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Build type is 'Release'
-- Performing Test BROTLI_EMSCRIPTEN
-- Performing Test BROTLI_EMSCRIPTEN - Failed
-- Compiler is not EMSCRIPTEN
-- Looking for log2
-- Looking for log2 - not found
-- Looking for log2
-- Looking for log2 - found
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_CXX_FLAGS
-- Build files have been written to: /root/lnmp2.0/src/ngx_brotli/deps/brotli/out
[ 3%] Building C object CMakeFiles/brotlicommon.dir/c/common/constants.c.o
[ 6%] Building C object CMakeFiles/brotlicommon.dir/c/common/context.c.o
[ 10%] Building C object CMakeFiles/brotlicommon.dir/c/common/dictionary.c.o
[ 13%] Building C object CMakeFiles/brotlicommon.dir/c/common/platform.c.o
[ 17%] Building C object CMakeFiles/brotlicommon.dir/c/common/shared_dictionary.c.o
[ 20%] Building C object CMakeFiles/brotlicommon.dir/c/common/transform.c.o
[ 24%] Linking C static library libbrotlicommon.a
[ 24%] Built target brotlicommon
[ 27%] Building C object CMakeFiles/brotlienc.dir/c/enc/backward_references.c.o
[ 31%] Building C object CMakeFiles/brotlienc.dir/c/enc/backward_references_hq.c.o
[ 34%] Building C object CMakeFiles/brotlienc.dir/c/enc/bit_cost.c.o
[ 37%] Building C object CMakeFiles/brotlienc.dir/c/enc/block_splitter.c.o
[ 41%] Building C object CMakeFiles/brotlienc.dir/c/enc/brotli_bit_stream.c.o
[ 44%] Building C object CMakeFiles/brotlienc.dir/c/enc/cluster.c.o
[ 48%] Building C object CMakeFiles/brotlienc.dir/c/enc/command.c.o
[ 51%] Building C object CMakeFiles/brotlienc.dir/c/enc/compound_dictionary.c.o
[ 55%] Building C object CMakeFiles/brotlienc.dir/c/enc/compress_fragment.c.o
[ 58%] Building C object CMakeFiles/brotlienc.dir/c/enc/compress_fragment_two_pass.c.o
[ 62%] Building C object CMakeFiles/brotlienc.dir/c/enc/dictionary_hash.c.o
[ 65%] Building C object CMakeFiles/brotlienc.dir/c/enc/encode.c.o
[ 68%] Building C object CMakeFiles/brotlienc.dir/c/enc/encoder_dict.c.o
[ 72%] Building C object CMakeFiles/brotlienc.dir/c/enc/entropy_encode.c.o
[ 75%] Building C object CMakeFiles/brotlienc.dir/c/enc/fast_log.c.o
[ 79%] Building C object CMakeFiles/brotlienc.dir/c/enc/histogram.c.o
[ 82%] Building C object CMakeFiles/brotlienc.dir/c/enc/literal_cost.c.o
[ 86%] Building C object CMakeFiles/brotlienc.dir/c/enc/memory.c.o
[ 89%] Building C object CMakeFiles/brotlienc.dir/c/enc/metablock.c.o
[ 93%] Building C object CMakeFiles/brotlienc.dir/c/enc/static_dict.c.o
[ 96%] Building C object CMakeFiles/brotlienc.dir/c/enc/utf8_util.c.o
[100%] Linking C static library libbrotlienc.a
[100%] Built target brotlienc
cd ../../../..
#返回
在lnmp.conf里Nginx_Modules_Options
添加ngx_brotli
模块源码绝对地址(如:--add-module=/root/lnmp2.0/src/ngx_brotli
),开始编译Nginx,这次编译速度很快,并且还成功了!
看来以后给Nginx编译增加Brotli算法支持最好挑个合适的时候呀,当然只要编译成功过一次的,也可以保留好1ngx_brotli1源码目录继续编译也是没有问题的。