How to Check Nginx Compiled Flags and Installed Modules


4 views

The simplest way to check compilation flags and modules is by running:

nginx -V

This will output all configuration parameters used during compilation, including:

  • Compilation flags (--with-*, --without-*)
  • Version information
  • Compiler version
  • Built-in modules

A typical output might look like:

nginx version: nginx/1.25.2
built by gcc 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04) 
built with OpenSSL 3.0.2 15 Mar 2022
TLS SNI support enabled
configure arguments: --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module

Here we can see SSL, HTTP/2, real IP, and status modules were included during compilation.

For installations with dynamic modules, check the modules directory:

ls /usr/lib/nginx/modules/ # Common path on Debian/Ubuntu
ls /etc/nginx/modules/     # Alternative path on some systems

To verify if a specific module is loaded at runtime (for both static and dynamic modules):

nginx -T 2>&1 | grep -i 'load_module'

For scripted environments, parse the version output:

#!/bin/bash
nginx -V 2>&1 | awk -F: '/^configure/{print $2}' | tr ' ' '\n' | grep '^--'

This will list all compilation flags in a clean format.

Some modules only reveal themselves in the active configuration:

nginx -T 2>&1 | grep -E '^(http|stream|mail)_'

This shows directives from various module groups currently in use.

Paths may vary across distributions:

  • Debian/Ubuntu: /etc/nginx/modules-enabled/
  • CentOS/RHEL: /usr/share/nginx/modules/
  • Alpine: /etc/nginx/conf.d/

When working with Nginx in production environments, it's often necessary to verify which compilation flags were used during installation and which modules are currently available. This information is crucial for debugging, performance tuning, and ensuring compatibility with specific features.

The most straightforward method is to use the -V flag (uppercase V) with the Nginx binary:

nginx -V

This command will output detailed information including:

  • Nginx version
  • Compiler used
  • Configure arguments (compilation flags)
  • Built-in modules

Here's a sample output and how to interpret it:

nginx version: nginx/1.18.0
built by gcc 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) 
configure arguments: --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module

To list all compiled modules (both static and dynamic):

nginx -V 2>&1 | grep -o 'with-http_[a-z_]*_module'

For a more readable format:

nginx -V 2>&1 | tr ' ' '\n' | grep '_module'

For Nginx installations with dynamic modules, you can check loaded modules in the configuration:

grep 'load_module' /etc/nginx/nginx.conf

Or check the modules directory:

ls /usr/lib/nginx/modules/

To confirm if SSL support is compiled in:

nginx -V 2>&1 | grep -q 'with-http_ssl_module' && echo "SSL supported" || echo "SSL not supported"

On different operating systems, the Nginx binary path might vary:

  • Linux: /usr/sbin/nginx
  • FreeBSD: /usr/local/sbin/nginx
  • Windows: C:\nginx\nginx.exe

If you don't have shell access, you can check via HTTP headers (if server-tokens is enabled):

curl -I http://yourserver.com | grep Server

Or examine the Nginx build configuration file if available:

cat /usr/lib/nginx/objs/ngx_auto_config.h

When encountering "unknown directive" errors, first verify if the required module is compiled in:

nginx -V 2>&1 | grep module_name

For example, to check for the GeoIP module:

nginx -V 2>&1 | grep 'with-http_geoip_module'