编译nginx

WARNING: This article may be obsolete
This post was published in 2022-07-02. Obviously, expired content is less useful to users if it has already pasted its expiration date.
This article is categorized as "Garbage" . It should NEVER be appeared in your search engine's results.

假设当前系统里已经安装好了一个可运行的nginx环境,现在我们给它的二进制可执行文件 nginx 进行一些改动:

tmux开一个新窗口

其中nginx的编译参数如下:

开启brotli(当前采用的方案)

2024年4月,我发现cloudflare已经支持从源服务器获取brotli格式编码的数据了,所以以后会默认编译带有brotli的nginx.

cd /root
rm -rf new_nginx
mkdir new_nginx
cd new_nginx
wget https://nginx.org/download/nginx-1.27.3.tar.gz
wget https://github.com/openssl/openssl/releases/download/openssl-3.3.2/openssl-3.3.2.tar.gz
wget https://github.com/PhilipHazel/pcre2/releases/download/pcre2-10.44/pcre2-10.44.tar.gz
# https://github.com/google/ngx_brotli
git clone --recurse-submodules -j8 https://github.com/google/ngx_brotli
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
cd ../../../..
# end brotli
wget https://github.com/madler/zlib/releases/download/v1.3.1/zlib-1.3.1.tar.gz
tar -xzf  nginx-1.27.3.tar.gz
tar -xzf openssl-3.3.2.tar.gz
tar -xzf pcre2-10.44.tar.gz
tar -xzf zlib-1.3.1.tar.gz
cd nginx-1.27.3
# https://github.com/google/ngx_brotli
# DO NOT USE IT
# export CFLAGS="-m64 -march=native -mtune=native -Ofast -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections"
# export LDFLAGS="-m64 -Wl,-s -Wl,-Bsymbolic -Wl,--gc-sections"
# end brotli conf
./configure --user=www --group=www --with-file-aio --with-threads --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-zlib=../zlib-1.3.1 --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_preread_module --with-stream_ssl_module --with-openssl=../openssl-3.3.2 --with-openssl-opt=enable-tls1_3 --with-http_gunzip_module --with-http_realip_module --with-pcre=../pcre2-10.44 --with-pcre-jit --add-module=../ngx_brotli
make -j `grep 'processor' /proc/cpuinfo | wc -l`

其中nginx的编译参数如下:

./configure --user=www --group=www --with-file-aio --with-threads --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-zlib=../zlib-1.3.1 --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_preread_module --with-stream_ssl_module --with-openssl=../openssl-3.3.2 --with-openssl-opt=enable-tls1_3 --with-http_gunzip_module --with-http_realip_module --with-pcre=../pcre2-10.44 --with-pcre-jit --add-module=../ngx_brotli

不开启brotli(暂时不用,所以版本不是最新)

由于不常用,所以下面的内容应该不是最新的。使用之前记得把所有版本号都更新到最新版。

不开启brotli,nginx二进制文件大小会减少大约6M .

cd /root
rm -rf new_nginx
mkdir new_nginx
cd new_nginx
wget https://nginx.org/download/nginx-1.25.4.tar.gz
wget https://www.openssl.org/source/openssl-3.2.1.tar.gz
wget https://github.com/PhilipHazel/pcre2/releases/download/pcre2-10.42/pcre2-10.42.tar.gz
wget https://github.com/madler/zlib/releases/download/v1.3.1/zlib-1.3.1.tar.gz
tar -xzf  nginx-1.25.4.tar.gz
tar -xzf openssl-3.2.1.tar.gz
tar -xzf pcre2-10.42.tar.gz
tar -xzf zlib-1.3.1.tar.gz
cd nginx-1.25.4
./configure --user=www --group=www --with-file-aio --with-threads --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-zlib=../zlib-1.3.1 --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_preread_module --with-stream_ssl_module --with-openssl=../openssl-3.2.1 --with-openssl-opt=enable-tls1_3 --with-http_gunzip_module --with-http_realip_module --with-google_perftools_module --with-pcre=../pcre2-10.42 --with-pcre-jit
make -j `grep 'processor' /proc/cpuinfo | wc -l`

其中nginx的编译参数如下:

./configure --user=www --group=www --with-file-aio --with-threads --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-zlib=../zlib-1.3.1 --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_preread_module --with-stream_ssl_module --with-openssl=../openssl-3.2.1 --with-openssl-opt=enable-tls1_3 --with-http_gunzip_module --with-http_realip_module --with-google_perftools_module --with-pcre=../pcre2-10.42 --with-pcre-jit


 Last Modified in 2024-11-28 

Leave a Comment Anonymous comment is allowed / 允许匿名评论