记CentOS编译nginx事务

环境须知

Nginx 版本:1.22.1

实施过程

开始编译 Nginx 之前,先参考编译语句

./configure arguments: --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log  --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --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_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-openssl=../openssl-1.0.2k --add-module=../lua-nginx-module-0.10.24 --add-module=../ngx_devel_kit-0.3.1

lua 是一个小巧的脚本语言,利用 lua-nginx-module 模块可以使用 lua 处理 nginx 请求

预先准备好 lua-nginx-module 和 ngx_devel_kit 在上级目录,注意版本号,且无需安装

1
2
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.24.tar.gz
tar zxvf v0.10.24.tar.gz
1
2
wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.1.tar.gz
tar zxvf v0.3.1.tar.gz

到这里可以真正开始编译,并键入make

倘若你本来就有 Nginx,现在是更新或覆盖安装,注意千万不要make install,不然就覆盖安装现有 nginx 了

正常情况下,会弹出以下错误

./configure: error: unsupported LuaJIT version; ngx_http_lua_module requires LuaJIT 2.x.

原因是缺少 LuaJIT 环境

1
2
3
wget https://github.com/openresty/luajit2/archive/refs/tags/v2.1-20220915.tar.gz
tar zxvf luajit2-2.1-20220915.tar.gz
sudo make install PREFIX=/usr/local/LuaJITL

然后再修改 lua-nginx-module 的 config 文件

1
2
3
# 直接声明这两个变量
LUAJIT_INC=/usr/local/LuaJIT/include/luajit-2.1
LUAJIT_LIB=/usr/local/LuaJIT/lib

然后继续开始 make 如无意外成功编译

问题

Q:使用 openresty 时 failed to load the resty.core module

问题是找不到 lualib 库和 resty 模块,默认到/usr/local/lib/ 去找 lualib,然而在编译安装 OpenResty 时 lualib 库默认放到/usr/local/openresty/lualib

作者

Catooilg

发布于

2023-05-19

更新于

2025-02-10

许可协议

评论