Nginx 模块在 Centos 7 上编译后不兼容二进制

Nginx 模块在 Centos 7 上编译后不兼容二进制

我需要使用 Nginx 模块ngx_http_auth_pam_module在 Centos 7 服务器上。由于软件包只能通过 getpagespeed 存储库获得,而该存储库不是免费的,所以我想自己编译它。

根据我找到的各种说明,我下载了模块和 Nginx 的源代码,列出了使用 安装的 Nginx 版本的编译选项,然后使用nginx -V编译模块,安装一些软件包以修复过程中的各种错误。./configuremake modules

但是,当我尝试配置 Nginx 以使用新编译的模块时,nginx -t出现了nginx: [emerg] module "/opt/nginx/modules/ngx_http_auth_pam_module.so" is not binary compatible in /usr/share/nginx/modules/mod-http-auth-pam.conf:1

据我所知,此“二进制不兼容”错误是由于安装的 Nginx 版本与模块中的编译标志不同,但我确保复制了 给出的所有内容nginx -V。我还确保下载了与安装的 Nginx 版本相同的源代码。

知道是什么原因导致此问题吗?我是否应该卸载 Nginx 并重新安装编译版本,还是这会带来自身的问题?

附录 :

以下是完整./configure命令:

./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --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-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --with-compat --add-dynamic-module=../ngx_http_auth_pam_module/

这里nginx -V

nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --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-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'

答案1

事实证明,该--with-compat选项导致了问题。我根据 nginx.com 上的指南添加了它,但在删除它并再次编译后,它nginx -t告诉我配置没有问题。

答案2

更兼容的方式:

  1. 通过以下方式获取当前 nginx 实例版本nginx -v
  2. 克隆 nginx 源代码并检出该标签,如“release-1.18.0”。
  3. 使用完全相同的选项配置源通过:
auto/configure --add-dynamic-module=/path/to/your/module `nginx -V`
  1. 制作

答案3

删除--with-compat选项不可能解决这个问题。

如果您收到有关使用此选项编译的二进制不兼容模块的错误,这仅意味着您为一个版本编译了它,但加载到了另一个版本中。例如,模块是针对 NGINX 源 1.16.0 编译的,而您在 NGINX 1.12.2 中加载(使用)它。顺便说一下,该版本非常旧,并且存在 HTTP/2 安全漏洞,因此您必须更新

如果有的话,也没什么理由不是使用--with-compat

我这样说很有偏见,但 GetPageSpeed repo 虽然对 CentOS 7 来说不是免费的(截至撰写本文时,对 CentOS/RHEL 8 是免费的),但它允许您始终获得新 NGINX 版本的最新模块,这些模块定期发布,解决新的安全问题以及增加的功能。否则,您必须不断地重新编译模块,而不是yum update,并可能最终在生产系统上使用编译软件。这本身就是一个安全问题。

GetPageSpeed 的替代方案是订阅 NGINX Plus,其费用远不止几美元。

答案4

要在 nginx 上启用 compat 模块,请在编译配置和 nginx 安装中创建动态模块之前尝试使用 --with-compat。这是我的 nginx 安装:

  1. ./configure --prefix=/opt/nginx --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-pcre --with-debug --with-http_stub_status_module --with-openssl--with-compat
  2. 制作
  3. 进行安装

然后尝试创建动态模块并从 nginx.conf 加载它。

高血压

相关内容