nginx在同一操作系统上编译构建好的是可以直接二进制分发的(主要是依赖gcc的版本)
download
特点:
jemalloc(优化对内存的分配管理)
lua (支持lua脚本)
nginx-v1.22.0
modules(支持session/upstream_check)
编译脚本 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 #!/bin/sh set -ebasedir=/servyou/nginx release_bin=${1:-nginx-v1.22.0-bin-c7.tar.gz} yum install -y gcc gcc-c++ make patch unzip -q cd dependsls *.tar.gz |xargs -n1 tar zxfcd -cd luals *.zip |xargs -n1 unzipcd -cd modulesls *.zip |xargs -n1 unzipcd -ls *.tar.gz |xargs -n1 tar zxfcd depends/jemalloc*./autogen.sh ./configure -q make -s -j2 && make -s install_bin install_include install_lib cd -cd lua/luajit*make -s -j2 && make -s install cd -echo "/usr/local/lib" > /etc/ld.so.conf.d/local.confldconfig export LUAJIT_LIB=/usr/local/libexport LUAJIT_INC=/usr/local/include/luajit-2.1cd nginx*./configure --prefix=$basedir \ --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module --with-stream --with-ld-opt="-ljemalloc" \ --add-module=./modules/nginx-goodies-nginx-sticky-module \ --add-module=../modules/nginx_upstream_check_module-master \ --add-module=../modules/echo-nginx-module-master \ --add-module=./modules/ngx_http_lua_module \ --add-module=../lua/ngx_devel_kit \ --with-pcre=../depends/pcre-8.37 \ --with-zlib=../depends/zlib-1.2.11 \ --with-openssl=../depends/openssl-1.0.2u make -s && make -s install rm -rf $basedir /htmlcp -a ../feature/* $basedir /cd -cd $basedir cp -a /usr/local/lib .cd ..tar zcf $release_bin nginx/ echo "building successful!!! $(ls $(dirname $basedir) )"
清理编译 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 #!/bin/sh ts=$(date +%F-%T) cd /usr/localmv lib{,_$ts }mv include{,_$ts }cd -cd dependsls -F |egrep /$ |xargs rm -rfcd -cd luals -F |egrep /$ |xargs rm -rfcd -cd modulesls -F |egrep /$ |xargs rm -rfcd -ngx_dir=$(ls |grep "nginx" |egrep -v "tar.gz$" ) rm -rf $ngx_dir echo "clean successful!!!"
使用注意 使用
tar zxf building-nginx-v1.22.0.tar.gz && cd building-nginx*
//编译
sh ngx_building.sh
默认构建成果$1 = nginx-v1.22.0-bin-c7.tar.gz
sh ngx_building.sh nginx-v1.22.0-bin-c6.tar.gz
sh ngx_clean.sh //清理后在次编译
注意: 编译好的二进制发行版本跟系统存在依赖关系,核心就是gcc的支持版本
c6就是centos6的发型版本
c7就是centos7的发型版本
如何使用构建好的二进制成果 echo '/servyou/nginx/lib' > /etc/ld.so.conf.d/ngx_local.conf
ldconfig
./sbinx/nginx -t //测试是否可以运行
如果不是默认的prefix则可以指定 -p
./sbinx/nginx -p /opt/nginx -t
reference