Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Nginx Modules Reference: Configuration Options and External Module Installation

Tech May 9 3

Nginx Built-in Modules

--prefix=/usr/local/nginx        # Installation directory
--sbin-path=/usr/local/nginx/sbin/nginx  # Binary executable path
--conf-path=/usr/local/nginx/conf/nginx.conf  # Configuration file path
--error-log-path=/var/log/nginx/error.log  # Error log location
--pid-path=/var/run/nginx.pid  # Process ID file
--lock-path=/var/lock/nginx.lock  # Lock file for atomic operations
--user=nginx  # Non-privileged user for worker processes
--group=nginx  # Non-privileged group for worker processes
--with-rtsig_module  # Real-time signal support
--with-select_module  # Select poll method (not recommended for high load)
--without-select_module  # Disable select module
--with-poll_module  # POLL poll method
--with-file-aio  # Asynchronous file I/O support
--with-ipv6  # IPv6 protocol support
--with-http_ssl_module  # HTTPS/SSL support (requires OpenSSL)
--with-http_realip_module  # Client IP address rewrite from headers
--with-http_addition_module  # Response filtering with appended content
--with-http_xslt_module  # XSLT transformation support
--with-http_image_filter_module  # Image filtering (JPEG/GIF/PNG processing)
--with-http_geoip_module  # Geographic IP-based variable creation
--with-http_sub_module  # Text substitution in responses
--with-http_dav_module  # WebDAV methods (PUT, DELETE, MKCOL, COPY, MOVE)
--with-http_flv_module  # FLV streaming support
--with-http_gzip_static_module  # Pre-compressed gzip responses
--with-http_random_index_module  # Random index file selection
--with-http_secure_link_module  # URL signature verification
--with-http_degradation_module  # Memory degradation handling
--with-http_stub_status_module  # Status page monitoring
--without-http_charset_module  # Disable charset re-encoding
--without-http_gzip_module  # Disable dynamic gzip compression
--without-http_ssi_module  # Disable Server Side Includes
--without-http_userid_module  # Disable user ID cookies
--without-http_access_module  # Disable IP-based access control
--without-http_auth_basic_module  # Disable Basic authentication
--without-http_autoindex_module  # Disable directory listing
--without-http_geo_module  # Disable geographic variables
--without-http_map_module  # Disable mapping variables
--without-http_split_clients_module  # Disable A/B testing split client
--without-http_referer_module  # Disable referer validation
--without-http_rewrite_module  # Disable URI rewrite
--without-http_proxy_module  # Disable proxy module
--without-http_fastcgi_module  # Disable FastCGI gateway
--without-http_uwsgi_module  # Disable uWSGI protocol
--without-http_scgi_module  # Disable SCGI protocol
--without-http_memcached_module  # Disable memcached integration
--without-http_limit_zone_module  # Disable connection limiting
--without-http_limit_req_module  # Disable request rate limiting
--without-http_empty_gif_module  # Disable empty GIF pixel
--without-http_browser_module  # Disable browser detection
--without-http_upstream_ip_hash_module  # Disable upstream IP hash load balancing
--with-http_perl_module  # Perl scripting support
--with-perl_modules_path=/usr/local/nginx/perl  # Perl module search path
--with-perl=/usr/local/lib/libperl.so  # Perl library path
--http-log-path=/var/log/nginx/access.log  # Access log location
--http-client-body-temp-path=/var/tmp/nginx/client  # Client request body cache
--http-proxy-temp-path=/var/tmp/nginx/proxy  # Proxy response cache
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi  # FastCGI response cache
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi  # uWSGI response cache
--http-scgi-temp-path=/var/tmp/nginx/scgi  # SCGI response cache
--without-http  # Disable HTTP server entirely
--without-http-cache  # Disable caching functionality
--with-mail  # Enable mail proxy (POP3/IMAP/SMTP)
--with-mail_ssl_module  # Mail SSL/TLS support
--without-mail_pop3_module  # Disable POP3 protocol
--without-mail_imap_module  # Disable IMAP protocol
--without-mail_smtp_module  # Disable SMTP protocol
--with-google_perftools_module  # Google Performance Tools profiling
--with-cpp_test_module  # C++ test module
--add-module=/path/to/external/module  # Enable third-party module
--with-cc=/usr/bin/gcc  # C compiler path
--with-cpp=/usr/bin/cpp  # C preprocessor path
--with-cc-opt="-I/usr/local/include -O2"  # C compiler options
--with-ld-opt="-L/usr/local/lib"  # Linker options
--with-cpu-opt=pentium4  # Target CPU architecture
--without-pcre  # Disable PCRE regex library
--with-pcre  # Enable PCRE library
--with-pcre=/usr/local  # PCRE library path
--with-pcre-opt="-O2"  # PCRE compilation options
--with-md5=/usr/local  # MD5 library path
--with-sha1=/usr/local  # SHA1 library path
--with-zlib=/usr/local  # zlib compression library path
--with-libatomic  # Atomic operations library
--with-openssl=/usr/local/openssl  # OpenSSL library path
--with-debug  # Enable debug logging

Compiling Nginx with Additional Modules

Prerequisites

Ensure Nginx is already installed. The binary can be replaced with a newly compiled version containing addditional modules.

Target Module

This example adds the echo module for debugging output capabilities.

Environment

  • Operating System: CentOS 7.3
  • Nginx Version: 1.8.0
  • Installation Path: /usr/local/nginx

Compilation Steps

  1. Download and extract the echo module:
wget https://github.com/openresty/echo-nginx-module/archive/v0.60.tar.gz
tar xf v0.60.tar.gz
  1. Create a module directory to preserve the module source:
mkdir /usr/local/nginx/module
mv echo-nginx-module-0.60 /usr/local/nginx/module/
  1. Display current compilation options:
nginx -V
  1. Configure with existing options plus the new module:
./configure \
    --prefix=/usr/local/nginx \
    --user=nginx \
    --group=nginx \
    --with-http_ssl_module \
    --with-http_spdy_module \
    --with-http_stub_status_module \
    --with-pcre \
    --add-module=/usr/local/nginx/module/echo-nginx-module-0.60/
  1. Compile the binary (do NOT run make install):
make
  1. Replace the Nginx binary:
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.backup
cp objs/nginx /usr/local/nginx/sbin/

Verification

nginx -t
nginx -s reload
nginx -V

Adding Modules to YUM-installed Nginx

Overview

When Nginx is installed via YUM, adding modules requires recompilation from source while preserving existing configuration.

Process

  1. Record existing compilation parameters:
nginx -V
  1. Obtain the matching source code version from nginx.org

  2. Configure with existing parameters plus new module paths:

./configure \
    [existing parameters] \
    --prefix=/tmp/nginx \
    --add-module=/path/to/new/module
make
make install
  1. Replace the binary:
cp /tmp/nginx/sbin/nginx /usr/sbin/nginx.new
mv /usr/sbin/nginx /usr/sbin/nginx.orig
cp /tmp/nginx/sbin/nginx /usr/sbin/nginx
  1. Verify:
nginx -V

External Modules

stub_status Module

Purpose

The stub_status module exposes server statistics including active connections and request counts.

Configuration

Compile with support:

./configure --with-http_stub_status_module

Add location block to server:

server {
    location /server-status {
        stub_status on;
        allow 127.0.0.1;
        deny all;
        access_log off;
    }
}

Response Format

Active connections: 5
server accepts handled requests
 5970806143 5970806143 7560482010
Reading: 0 Writing: 5 Waiting: 0
  • Active connections: Current connections to upstream servers
  • Server acepts handled requests: Total connections accepted, handshakes completed, requests processed
  • Reading: Connections reading request headers
  • Writing: Connections sending response headers
  • Waiting: Idle keepalive connections (active - reading - writing)

nginx_upstream_check_module

Purpose

This module provides active health checking for upstream servers, automatically detecting failed backends.

Source

https://github.com/yaoweibin/nginx_upstream_check_module

Configuration

  1. Download and extract:
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz
  1. Add module path during configure:
--add-module=/path/to/nginx_upstream_check_module
  1. Define upstream with health checks:
upstream backend {
    server 192.168.1.11:8080;
    server 192.168.1.12:8080;
    
    check interval=3000 rise=2 fall=3 timeout=3000 type=http;
    check_http_send "GET /health HTTP/1.0\r\n\r\n";
    check_http_expect_alive http_2xx http_3xx;
}
  1. Add status location:
server {
    location /health-status {
        check_status;
        access_log off;
    }
}

echo Module

Purpose

The echo module enables debug output within configuration blocks, useful for testing and troubleshooting.

Source

https://github.com/openresty/echo-nginx-module

Usage

location /debug {
    echo "Request received from $remote_addr";
    echo "Method: $request_method";
    echo "URI: $request_uri";
}

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.