FAQ

Page Discussion Edit History

NginxModules

Contents

Edit section: Compiling Nginx Compiling Nginx

Nginx modules must be selected at compile-time. A full summary of the compile-time options, including optional modules, can be found in the install guide.

Example:

./configure \
  --prefix=/usr \
  --sbin-path=/usr/sbin/nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --error-log-path=/var/log/nginx/error.log \
  --pid-path=/var/run/nginx/nginx.pid  \
  --lock-path=/var/lock/nginx.lock \
  --user=nginx \
  --group=nginx \
  --with-http_ssl_module \
  --with-http_flv_module \
  --with-http_gzip_static_module \
  --http-log-path=/var/log/nginx/access.log \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ 

The most current list of modules and compile options is always available with "./configure --help"

Edit section: Nginx Core Modules Nginx Core Modules

These modules are required.

Edit section: Main Module Main Module

Configure error logging, processes, permissions, etc.

user nginx;
worker_processes 2;

error_log logs/error.log;
pid logs/nginx.pid;

worker_rlimit_nofile 8192;

[Documentation]

Edit section: Events Module Events Module

Configure epoll, kqueue, select, poll, etc.

events {
  use kqueue; 
  worker_connections  4096;
}

[Documentation]


Edit section: Standard HTTP Modules Standard HTTP Modules

These modules are automatically compiled in unless explicitly disabled with configure.

Edit section: HTTP Core HTTP Core

Control ports, locations, error pages, aliases, and other essentials.

http {
  sendfile     on;
  tcp_nopush   on;

  server { 
    listen 80;
  }
}

[Documentation]

Edit section: HTTP Upstream HTTP Upstream

For load-balancing.

upstream backend  {
  server b1.example.com weight=5;
  server b2.example.com:81;
  server unix:/tmp/backend3;
}

server {
  location / {
    proxy_pass  http://backend;
  }
}

[Documentation]

Edit section: HTTP Access HTTP Access

Allow/deny based on IP address.

location / {
  deny    192.168.1.1;
  allow   192.168.1.0/24;
  allow   10.1.1.0/16;
  deny    all;
}

[Documentation]

Edit section: HTTP Auth Basic HTTP Auth Basic

Basic HTTP authentication.

location  /  {
  auth_basic "Restricted";
  auth_basic_user_file conf/htpasswd;
}

[Documentation]


Edit section: HTTP Auto Index HTTP Auto Index

Generates automatic directory listings.

location  /  {
  autoindex  on;
}

[Documentation]

Edit section: Browser Browser

Interpret "User-Agent" string.

ancient_browser Links Lynx Netscape4;

if ($ancient_browser){
  rewrite ^ /ancient.html;
}

[Documentation]

Edit section: Charset Charset

Recode web pages.

charset windows-1251;
source_charset koi8-r;

[Documentation]

Edit section: Empty GIF Empty GIF

Serve a 1x1 image from memory.

location = /1x1.gif {
  empty_gif;
}

[Documentation]

Edit section: FastCGI FastCGI

FastCGI Support.

location \.php$ {
  include fastcgi_conf;
  fastcgi_pass localhost:9000;
  fastcgi_index index.php;
}

[Documentation]

Edit section: Geo Geo

Set config variables using key/value pairs of IP addresses.

geo $geo {
  default          0;
  127.0.0.1/32     2;
  192.168.1.0/24   1;
  10.1.0.0/16      1;
}

[Documentation]

Edit section: Gzip Gzip

Gzip responses.

gzip on;
gzip_min_length 1000;
gzip_types text/plain application/xml;
gzip_disable "MSIE [1-6]\.";

[Documentation]

Edit section: HTTP Headers HTTP Headers

Set arbitrary HTTP response headers.

expires 24h;
add_header Cache-Control private;

[Documentation]

Edit section: Index Index

Controls which files are to be used as index.

location / {
  index index.html index.htm;
}

[Documentation]

Edit section: HTTP Referer HTTP Referer

Filter requests based on Referer header.

location /photos/ {
  valid_referers none blocked 
                 www.mydomain.com 
                 mydomain.com;

  if ($invalid_referer) {
    return 403;
  }
}

[Documentation]

Edit section: HTTP Limit Zone HTTP Limit Zone

Limit simultaneous connections from a client.

http {
  limit_zone one $binary_remote_addr 10m;

  server {
    location /download/ {
      limit_conn one 1;
    }
  }
}

[Documentation]

Edit section: HTTP Limit Requests HTTP Limit Requests

Limit frequency of connections from a client.

http {
    limit_req_zone  $binary_remote_addr \
       zone=one:10m   rate=1r/s;
    server {
        location /search/ {
            limit_req   zone=one  burst=5;
        }
    }
}

[Documentation]


Edit section: Log Log

Customize access logs.

 
access_log /var/logs/nginx/access.log
           gzip
           buffer=32k;

[Documentation]

Edit section: Map Map

Set config variables using arbitrary key/value pairs.

map $http_host $name  {
  hostnames;

  default          0;
  example.com      1;
  *.example.com    1;
  test.com         2;
  *.test.com       2;
  .site.com        3;
}

[Documentation]

Edit section: Memcached Memcached

Memcached support.

server {
  location / {
    set $memcached_key $uri;
    memcached_pass name:11211;
    default_type text/html;
    error_page 404 = /fallback;
  }

  location = /fallback {
    proxy_pass backend;
  }
}

[Documentation]

Edit section: HTTP Proxy HTTP Proxy

Proxy to upstream servers.

location / {
  proxy_pass http://localhost:8000;
  proxy_set_header X-Real-IP $remote_addr;
}

[Documentation]

Edit section: Rewrite Rewrite

Request rewriting using regular expressions.

location /en {
  rewrite ^/en/(.*)$ /($1)?lang=en last;
}

[Documentation]

Edit section: SSI SSI

Server-side includes.

location / {
  ssi on;
}

[Documentation]

Edit section: User ID User ID

Issue identifying cookies.

userid on;
userid_name uid;
userid_domain example.com;
userid_path /;
userid_expires 365d;

[Documentation]


Edit section: Optional HTTP modules Optional HTTP modules

The following modules must be enabled at compile-time with the specified option to configure.

Edit section: HTTP Addition HTTP Addition

Append text to pages.

--with-http_addition_module

location / {
  add_before_body /before_action;
  add_after_body /after_action;
}

[Documentation]

Edit section: Embedded Perl Embedded Perl

Use Perl in Nginx config files.

--with-http_perl_module

[Documentation]

Edit section: FLV FLV

Flash Streaming Video

--with-http_flv_module

[Documentation]

Edit section: Gzip Precompression Gzip Precompression

--with-http_gzip_static_module

[Documentation]

Edit section: Random Index Random Index

Randomize directory indexes.

--with-http_random_index_module

[Documentation]

Edit section: GeoIP GeoIP

Creates variables with information from the MaxMind GeoIP binary files.

--with-http_geoip_module

[Documentation]


Edit section: Real IP Real IP

For using nginx as backend

--with-http_realip_module

[Documentation]

Edit section: SSL SSL

HTTPS/SSL support.

--with-http_ssl_module

[Documentation]

Edit section: Stub Status Stub Status

View server statistics.

--with-http_stub_status_module

[Documentation]

Edit section: Substitution Substitution

Replace text in pages

--with-http_sub_module

[Documentation]

Edit section: WebDAV WebDAV

WebDAV pass-through support.

--with-http_dav_module

[Documentation]

Edit section: Google Perftools Google Perftools

Google Performance Tools support.

--with-google_perftools_module

[Documentation]

Edit section: XSLT XSLT

Post-process pages with XSLT.

--with-http_xslt_module

[Documentation]

Edit section: Secure Link Secure Link

Protect pages with a secret key.

--with-http_secure_link_module

[Documentation]


Edit section: Image Filter Image Filter

Transform images with Libgd

--with-http_image_filter_module

[Documentation]



Edit section: Mail modules Mail modules

Edit section: Mail Core Mail Core

Nginx is able to handle and proxy the IMAP, POP3, SMTP protocols.

Mail Core Module

Edit section: Mail Auth Mail Auth

Use Nginx to authenticate mail services.

Mail Auth Module

Edit section: Mail Proxy Mail Proxy

Mail Proxy Module

Edit section: Mail SSL Mail SSL

This module ensures SSL/TLS support for POP3/IMAP/SMTP.

Mail SSL Module


Edit section: Third-Party modules and patches Third-Party modules and patches

Please see the catalog of 3rd party modules.

Edit section: References References