2026-05-29T11:49:55.606ZLinuxNginx
Nginx之Lua模块lua-nginx-module编译和配置
安装Lua模块lua-nginx-module
准备工作
- 下载对应模块
# luajit2
git clone https://github.com/openresty/luajit2.git
# lua-nginx-module模块
git clone https://github.com/openresty/lua-nginx-module2.git
# ngx_devel_kit
wget https://github.com/vision5/ngx_devel_kit/archive/refs/tags/v0.3.4.tar.gz
- 编译安装luajit2
cd luajit2/
make && make install

- 在/etc/profile里面添加
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.1
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

- 刷新配置
source /etc/profile
- 验证luajit是否生效
luajit -v

- 编译nginx
./configure \
--prefix=/opt/nginx \
--with-compat \
--with-file-aio \
--with-threads \
--without-http_upstream_keepalive_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-openssl-opt='enable-weak-ssl-ciphers' \
--with-threads \
--with-stream \
--with-mail \
--with-pcre \
--with-mail_ssl_module \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-debug \
--with-pcre-jit \
--with-stream_ssl_module \
--with-http_slice_module \
--with-file-aio \
--with-http_v2_module \
--with-http_v3_module \
--without-http_rewrite_module \
--with-ld-opt="-Wl,-rpath,/usr/local/lib" \
--with-cc-opt="-I/usr/local/include/luajit-2.1" \
--add-dynamic-module=/opt/nginx/modules/lua-nginx-module \
--add-dynamic-module=/opt/nginx/modules/ngx_devel_kit-0.3.4
make && make install

- 验证模块是否正常安装
nginx -V
