关于 DreamCat

主题名称:DreamCat | 版本:3.0.240224

主题开发:HanFengA7 | CornWorld

Designed by HanFengA7 Power by Typecho

Copyright © 2015-2024 by LychApe All rights reserved!

menu
refresh

为Openresty编译module

作者: ciaoℒy

时间:

Openresty还是挺香的, 但是当需要使用Nginx的module时有点抓瞎了: 使用apt安装的 ngx-module-* 往往和Openresty的版本声明不太一样, 相应的*.so文件也基本上不能用的了. 所以就需要自己编译module了.

如果是自己从零开始编译安装Openresty和ngx-module-*的话, 按照官方教程进行即可. 但是我的Openresty是使用官方的PPA源安装的, 因此编译的时候就需要与官方编译参数一致了, 不然的话编译完之后的.so在加载时就会报这个一个错误:

nginx is not binary compatible ...

正确的编译步骤如下所示:

  1. 下载Openresty的源码和要安装的模块的源码(例如ngx_http_geoip2_module)

  2. 进入到Openresty源码中的bundle/nginx-VERSION/目录下
  3. 导出必要的环境变量:
export LUAJIT_LIB="/usr/local/openresty/luajit/lib/" #这里是系统中已安装的Openresty/luajit的目录
export LUAJIT_INC="../LuaJIT-VERSION/src/" #VERSION是指下载的Openresty源码中的LuaJIT的版本号
  1. 获取Openresty的编译参数:
COMPILEOPTIONS=$(openresty -V 2>&1|grep -i "arguments"|cut -d ":" -f2-)
  1. 在当前目录下编译模块:
eval ./configure $COMPILEOPTIONS --add-dynamic-module=path/to/ngx_http_geoip2_module
make modules
  1. 将编译之后的模块复制到Openresty相应的目录下, 重新加载Openresty即可

参考: Building dynamic modules for openresty - OpenResty Forum


#本文链接:https://blog.chaol.top/archives/65.html
#本文采用 CC BY-NC-SA 4.0 协议进行许可
#如无特别声明,该文章均为 ciaoℒy 原创,转载请遵循 署名-非商业性使用 4.0 国际(CC BY-NC 4.0)协议,即转载请注明文章来源。
#最后编辑时间为: 2022 年 10 月 17 日
none

create 添加新评论


account_circle
email
language
textsms



加我的QQ
加我的微博
加我的支付宝
加我的微信