Optimal Installation Path for Nginx Dynamic Modules: Where to Place Binary Module Files Like nginx_ajp_module


3 views

Nginx typically expects dynamic modules to be placed in the module directory specified during compilation. The standard locations vary based on installation method:

# Default paths for common installation methods
1. Official NGINX packages: /usr/lib/nginx/modules/
2. Compiled from source: /usr/local/nginx/modules/
3. Debian/Ubuntu packages: /usr/share/nginx/modules-available/

Check your nginx configuration to find the exact module path:

nginx -V 2>&1 | grep --color -oP '(?<=--modules-path=)\S+'

Or examine the nginx.conf file for load_module directives:

grep -r "load_module" /etc/nginx/

For the nginx_ajp_module example, follow these steps:

# Compile the module
git clone https://github.com/yaoweibin/nginx_ajp_module.git
cd nginx_ajp_module
./configure --add-module=$(pwd)
make

# Install to standard location
sudo cp objs/ngx_http_ajp_module.so /usr/lib/nginx/modules/

After placing the module, add this to nginx.conf:

load_module modules/ngx_http_ajp_module.so;

http {
    upstream tomcat {
        ajp_pass 127.0.0.1:8009;
    }
}
  • Keep modules organized by version if running multiple nginx instances
  • Use absolute paths in load_module directives for clarity
  • Document all installed modules in a README file

Nginx typically expects module binaries to be located in its modules directory, which varies based on installation method:

# For default package installations:
/usr/lib/nginx/modules/  # Common on Debian/Ubuntu
/usr/lib64/nginx/modules/ # Common on CentOS/RHEL

# For source installations:
/usr/local/nginx/modules/

To find your exact module directory, check the nginx configuration:

nginx -V 2>&1 | grep -o '\\-\\-modules\\-path=[^ ]*'
# Example output:
--modules-path=/usr/lib/nginx/modules

For the nginx_ajp_module, here's the complete installation process:

# Clone the module
git clone https://github.com/yaoweibin/nginx_ajp_module.git
cd nginx_ajp_module

# Compile as dynamic module
./configure --add-dynamic-module=./nginx_ajp_module
make
sudo make install

# Move to correct directory (example for Ubuntu)
sudo cp objs/ngx_http_ajp_module.so /usr/lib/nginx/modules/

After placing the module in the correct directory, add this to nginx.conf:

load_module modules/ngx_http_ajp_module.so;

Check if the module loaded successfully:

nginx -t  # Test configuration
nginx -T | grep ajp  # Check loaded modules

If you encounter "module not found" errors:

  1. Verify the module directory exists and has proper permissions
  2. Check the module is compiled for the exact nginx version
  3. Ensure the load_module path is relative to nginx prefix