准备工作

编译

#从官网下载合适的版本并解压
nginx_version=1.17.5
wget -O- "http://nginx.org/download/nginx-$nginx_version.tar.gz" | tar xz

#进入编译目录
cd nginx-$nginx_version

#下载依赖文件并解压
wget -O- "https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz" | tar xz
wget -O- "https://zlib.net/fossils/zlib-1.2.11.tar.gz" | tar xz

#编译,下面的 LDFLAGS 和 CFLAGS 需要设置成 OpenSSL 的路径
NGX_PREFIX=/tmp ./configure --error-log-path=/dev/null --http-log-path=/dev/null \
	--prefix=/usr/local/nginx \
	--with-cc-opt="-static -static-libgcc" \
	--with-ld-opt="-static" --with-cpu-opt=generic \
	--with-http_addition_module --with-pcre=./pcre-8.43 \
	--with-zlib=./zlib-1.2.11 --with-http_slice_module
make -j $(grep "cpu cores" /proc/cpuinfo | wc -l)

#处理编译好的二进制文件
mv objs/nginx ../nginx_x64
strip ../nginx_x64

编译完之后,就可以删除源文件了

cd ..
rm -rf nginx-$nginx_version

下载

编译好的文件