How to Fix “Nginx Module Not Binary Compatible” Error When Compiling ngx_http_auth_pam_module on CentOS 7


4 views

When you encounter the "module is not binary compatible" error in Nginx, it typically means there's a mismatch between:

  1. The exact Nginx version used during module compilation
  2. The compiler flags and options used
  3. The system libraries linked against
  4. The architecture-specific compilation parameters

First, confirm all critical components match exactly:

# Check installed Nginx version and build parameters
nginx -V

# Verify GCC version
gcc --version

# Check OpenSSL version
openssl version

Here's the proper way to compile the module for your specific CentOS 7 environment:

# Install required dependencies
sudo yum install -y gcc make pcre-devel zlib-devel openssl-devel pam-devel

# Download matching Nginx source
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar zxvf nginx-1.12.2.tar.gz

# Download auth_pam module
git clone https://github.com/sto/ngx_http_auth_pam_module.git

# Configure with EXACTLY the same parameters
cd nginx-1.12.2
./configure \
--prefix=/usr/share/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules \
[... ALL OTHER ORIGINAL PARAMETERS ...] \
--add-dynamic-module=../ngx_http_auth_pam_module

# Build just the module
make modules

# Copy the compiled module
cp objs/ngx_http_auth_pam_module.so /usr/lib64/nginx/modules/
chmod 644 /usr/lib64/nginx/modules/ngx_http_auth_pam_module.so

Verify these often-missed details:

  • The module was compiled with the exact same --with-cc-opt and --with-ld-opt flags
  • The RPM build environment variables match (important for CentOS/RHEL)
  • All dynamically linked libraries are identical versions

If you still face issues, consider building Nginx completely from source:

# After configuration
make
sudo make install

# Then verify the module loads
nginx -t

Compare library dependencies between Nginx and your module:

ldd /usr/sbin/nginx
ldd /usr/lib64/nginx/modules/ngx_http_auth_pam_module.so

Any discrepancies in library versions will cause binary incompatibility.

After successful compilation, configure Nginx to use PAM authentication:

load_module modules/ngx_http_auth_pam_module.so;

http {
    server {
        location /secure {
            auth_pam "Restricted Area";
            auth_pam_service_name "nginx";
            # PAM configuration in /etc/pam.d/nginx required
        }
    }
}

The "not binary compatible" error typically occurs when there's a mismatch between:

  • Nginx version used for compilation vs installed version
  • Compiler flags used during module compilation vs original Nginx build
  • Library dependencies (especially OpenSSL/PAM versions)
  • Architecture-specific compilation parameters

First, let's verify the exact environment matches:

# Check exact Nginx package details
rpm -qi nginx

# Verify compiler version matches
gcc --version

# Check OpenSSL version
openssl version

# Verify all dependencies
ldd /usr/sbin/nginx
ldd /opt/nginx/modules/ngx_http_auth_pam_module.so

Here's the correct way to compile the module with guaranteed compatibility:

# Install prerequisites
sudo yum install -y gcc make pcre-devel zlib-devel openssl-devel pam-devel

# Download exact matching Nginx source
NGINX_VERSION=$(nginx -v 2>&1 | awk -F'/' '{print $2}')
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
tar zxvf nginx-${NGINX_VERSION}.tar.gz

# Clone module repo
git clone https://github.com/sto/ngx_http_auth_pam_module.git

# Extract configure arguments from installed Nginx
CONFIGURE_ARGS=$(nginx -V 2>&1 | grep "configure arguments" | cut -d':' -f2-)

# Reconfigure with --with-compat flag
cd nginx-${NGINX_VERSION}
./configure $CONFIGURE_ARGS --with-compat \
--add-dynamic-module=../ngx_http_auth_pam_module

# Build just the module (not full Nginx)
make modules

After successful compilation, verify the module compatibility:

# Check module symbols against Nginx binary
nm -D /usr/sbin/nginx | grep ngx_module
nm -D objs/ngx_http_auth_pam_module.so | grep ngx_module

# Test loading the module
sudo nginx -t -c /etc/nginx/nginx.conf

If compatibility issues persist, consider rebuilding Nginx entirely:

# Backup current configuration
sudo cp -r /etc/nginx{,.bak}

# Remove existing package
sudo yum remove nginx

# Complete rebuild with module integrated
./configure $CONFIGURE_ARGS \
--add-module=../ngx_http_auth_pam_module

make
sudo make install

# Restore configuration
sudo cp -r /etc/nginx.bak/* /etc/nginx/

For deeper analysis, these tools can help identify mismatches:

# Check ELF headers
readelf -h /usr/sbin/nginx
readelf -h objs/ngx_http_auth_pam_module.so

# Verify symbol versions
objdump -T /usr/sbin/nginx | head
objdump -T objs/ngx_http_auth_pam_module.so | head

# Check compiler flags used
strings /usr/sbin/nginx | grep GCC
strings objs/ngx_http_auth_pam_module.so | grep GCC

Once resolved, here's a sample PAM configuration:

location /secure {
    auth_pam "Secure Zone";
    auth_pam_service_name "nginx";
    proxy_pass http://backend;
}

And the corresponding PAM configuration (/etc/pam.d/nginx):

auth    required    pam_unix.so
account required    pam_unix.so