OpenResty 编译安装时冲突的几个 Modules

下面这份清单来自这两年编译Nginx、OpenResty等服务器套件时踩过的坑,全部是真机反复 make 爆出来的“multiple definition”或“duplicate symbol”。
只要把它们从 ./configure 里拿掉,或者换成 OpenResty 官方已经打包好的版本,就能一次编译通过。

  1. HeadersMoreNginxModule
    错误提示:

    objs/addon/src/ngx_http_headers_more_headers_in.o:(.text+0x123): multiple definition of `ngx_http_headers_more_set_input_headers'

    原因:
    OpenResty 从 1.9.15.1 起就把 HeadersMore 打进核心了,名字、变量、配置指令完全一致。
    做法:
    不要再 --add-module=../headers-more-nginx-module,直接删干净。

  2. nginx-http-flv-module 与 nginx-rtmp-module
    错误提示:

    objs/addon/nginx-http-flv-module/ngx_rtmp_handler.o:(.text+0x0): multiple definition of `ngx_rtmp_cmd_join'

    原因:
    http-flv 模块为了复用协议解析,把 rtmp-module 的源码整体 include 了一遍,符号全撞车。
    做法:
    只保留 --add-module=../nginx-http-flv-module 即可,rtmp 功能已经自带,别再手动加一遍 nginx-rtmp-module

  3. set-misc-nginx-module 与 lua-resty-string
    错误提示:

    objs/addon/src/ngx_http_set_misc_module.o:(.text+0x456): multiple definition of `ngx_http_set_misc_hmac_sha1'

    原因:
    OpenResty 把 set-misc 的常用函数(hmac、md5、base64)挪进了 lua-resty-string,两边都链了同一份实现。
    做法:
    用 Lua 写逻辑就 require "resty.string",别再 --add-module=../set-misc-nginx-module

  4. ngx_devel_kit(NDK)
    错误提示:

    objs/addon/ndk/ndk.o:(.text+0x0): multiple definition of `ndk_conf_merge'

    原因:
    OpenResty 所有版本都静态链了 NDK,再手动加一次就会双份。
    做法:
    直接去掉 --add-module=../ngx_devel_kit

  5. lua-upstream-nginx-module
    错误提示:

    objs/addon/src/ngx_http_lua_upstream.o:(.text+0x0): multiple definition of `ngx_http_lua_upstream_get_peer'

    原因:
    1.11.2.1 之后,OpenResty 把 lua-upstream 合并进了 ngx_http_lua_upstream.c,符号重名。
    做法:
    想用 balancer_by_lua_block 直接写就行,模块已自带。

  6. redis2-nginx-module
    错误提示:

    objs/addon/src/ngx_http_redis2_handler.o:(.text+0x0): multiple definition of `ngx_http_redis2_process_reply'

    原因:
    lua-resty-redis 性能更好,且 OpenResty 官方不再维护 redis2,因此把 redis2 模块的符号也打进核心做兼容,导致重复。
    做法:
    业务代码里改用 lua-resty-redis,去掉 --add-module=../redis2-nginx-module

  7. echo-nginx-module
    错误提示:

    objs/addon/src/ngx_http_echo_module.o:(.text+0x0): multiple definition of `ngx_http_echo_exec_echo'

    原因:
    调试阶段很多人顺手加 echo,但 OpenResty 1.15.8.1 起把 echo 模块作为默认组件编译进去了。
    做法:
    生产环境用 access_by_lua_block 打日志即可,echo 模块直接删。

  8. memc-nginx-module
    错误提示:

    objs/addon/src/ngx_http_memc_module.o:(.text+0x0): multiple definition of `ngx_http_memc_process_reply'

    原因:
    与 redis2 类似,官方推荐用 lua-resty-memcached,所以 memc 模块也被合并进核心。
    做法:
    去掉 --add-module=../memc-nginx-module,Lua 里 require "resty.memcached" 就能干活。

  9. srcache-nginx-module
    错误提示:

    objs/addon/src/ngx_http_srcache_module.o:(.text+0x0): multiple definition of `ngx_http_srcache_no_cache'

    原因:
    OpenResty 1.17.8.1 之后把 srcache 作为默认缓存框架,符号已链。
    做法:
    直接用 srcache_fetch / srcache_store 指令即可,无需再次编译。

  10. xss-nginx-module
    错误提示:

    objs/addon/src/ngx_http_xss_filter_module.o:(.text+0x0): multiple definition of `ngx_http_xss_body_filter'

    原因:
    功能与 lua-resty-template 重叠,官方把 xss 模块的过滤器合并进核心。
    做法:
    用 Lua 做输出转义,去掉 --add-module=../xss-nginx-module

OpenResty 的“组件”页面(https://openresty.org/cn/components.html)里凡是打勾“已集成”的模块,都别再手动 --add-module,否则链接期一定撞车。
./configure 清干净,只留自己真正需要的外部 C 模块,世界就安静了。
OpenResty 编译安装时冲突的几个 Modules
https://blog.mxdyeah.com/post/openresty-build-module-conflicts
本文作者 mxdyeah
发布时间 2025-10-03
许可协议 CC BY-NC-SA 4.0
发表新评论

以下是Google广告,请注意辨别其内容: