安装路径为/home/nginx/nginx,编译目录在/home/nginx/nginx_install下

yum install -y gcc gcc-c++ make automake autoconf libtool zlib-devel openssl-devel

下载源码包

wget https://nginx.org/download/nginx-1.28.0.tar.gz
wget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/08a395c66e425540982c00482f55034e1fee67b6.tar.gz
wget https://github.com/nbs-system/naxsi/archive/refs/tags/0.55.3.tar.gz
wget https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1w/openssl-1.1.1w.tar.gz
wget https://github.com/openresty/lua-nginx-module/archive/refs/tags/v0.10.28.tar.gz
wget https://github.com/vision5/ngx_devel_kit/archive/refs/tags/v0.3.4.tar.gz
wget https://github.com/openresty/luajit2/archive/refs/tags/v2.1-20250529.tar.gz
wget https://github.com/openresty/lua-resty-lrucache/archive/refs/tags/v0.15.tar.gz
wget https://github.com/openresty/lua-resty-core/archive/refs/tags/v0.1.31.tar.gz
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/refs/tags/v0.4.0.tar.gz
tar xf nginx-1.28.0.tar.gz
tar xf 08a395c66e425540982c00482f55034e1fee67b6.tar.gz
tar xf 0.55.3.tar.gz
tar xf openssl-1.1.1w.tar.gz
tar xf v0.10.28.tar.gz
tar xf v0.3.4.tar.gz
tar xf v2.1-20250529.tar.gz
tar xf v0.15.tar.gz
tar xf v0.1.31.tar.gz
tar xf v0.4.0.tar.gz

编译lua环境

cd luajit2-2.1-20250529
make && make install PREFIX=/home/nginx/nginx/lj2-2.1
export LUAJIT_LIB=/home/nginx/nginx/lj2-2.1/lib
export LUAJIT_INC=/home/nginx/nginx/lj2-2.1/include/luajit-2.1
cd ../lua-resty-core-0.1.31
make install PREFIX=/home/nginx/nginx/lualib LUA_LIB_DIR=$LUAJIT_LIB/lua/5.1
cd ../lua-resty-lrucache-0.15
make install PREFIX=/home/nginx/nginx/lualib LUA_LIB_DIR=$LUAJIT_LIB/lua/5.1

nginx-sticky-module模块版本太老,需要修改部分代码

cd /home/nginx/nginx_install/nginx-goodies-nginx-sticky-module-ng-08a395c66e42
sed -i "s/&r->headers_in.cookies/r->headers_in.cookie/g" ngx_http_sticky_module.c
sed -i '207s/.*/    if (ngx_http_parse_multi_header_lines(r, r->headers_in.cookie, \&iphp->sticky_conf->cookie_name, \&route) != NULL) {/' ngx_http_sticky_module.c

nginx_upstream_check_module模块需要打补丁

cd /home/nginx/nginx_install/nginx-1.28.0
patch -p1 < ../nginx_upstream_check_module-0.4.0/check_1.20.1+.patch

配置编译

./configure  --prefix=/home/nginx/nginx --with-http_v2_module --with-http_stub_status_module --with-http_ssl_module --add-module=/home/nginx/nginx_install/ngx_devel_kit-0.3.4/ --add-module=/home/nginx/nginx_install/lua-nginx-module-0.10.28/ --add-module=/home/nginx/nginx_install/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ --add-module=/home/nginx/nginx_install/nginx_upstream_check_module-0.4.0/ --add-module=/home/nginx/nginx_install/naxsi-0.55.3/naxsi_src/ --with-openssl=/home/nginx/nginx_install/openssl-1.1.1w/ --with-stream
make -j$(nproc) && make install
sed -i '/http {/a \    lua_package_path "/home/nginx/nginx/lj2-2.1/lib/lua/5.1/?.lua;;";' /home/nginx/conf/nginx.conf

安装完成

[nginx@localhost sbin]$ cd /home/nginx/nginx/sbin
[nginx@localhost sbin]$ ./nginx -V
nginx version: nginx/1.28.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.1.1w  11 Sep 2023
TLS SNI support enabled
configure arguments: --prefix=/home/nginx/nginx --with-http_v2_module --with-http_stub_status_module --with-http_ssl_module --add-module=/home/nginx/nginx_install/ngx_devel_kit-0.3.4/ --add-module=/home/nginx/nginx_install/lua-nginx-module-0.10.28/ --add-module=/home/nginx/nginx_install/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ --add-module=/home/nginx/nginx_install/nginx_upstream_check_module-0.4.0/ --add-module=/home/nginx/nginx_install/naxsi-0.55.3/naxsi_src/ --with-openssl=/home/nginx/nginx_install/openssl-1.1.1w/ --with-stream