NginxModules
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"
Nginx Core Modules
These modules are required.
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;
Events Module
Configure epoll, kqueue, select, poll, etc.
events {
use kqueue;
worker_connections 4096;
}
Standard HTTP Modules
These modules are automatically compiled in unless explicitly disabled with configure.
HTTP Core
Control ports, locations, error pages, aliases, and other essentials.
http {
sendfile on;
tcp_nopush on;
server {
listen 80;
}
}
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;
}
}
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;
}
HTTP Auth Basic
Basic HTTP authentication.
location / {
auth_basic "Restricted";
auth_basic_user_file conf/htpasswd;
}
Browser
Interpret "User-Agent" string.
ancient_browser Links Lynx Netscape4;
if ($ancient_browser){
rewrite ^ /ancient.html;
}
FastCGI
FastCGI Support.
location \.php$ {
include fastcgi_conf;
fastcgi_pass localhost:9000;
fastcgi_index index.php;
}
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;
}
Gzip
Gzip responses.
gzip on; gzip_min_length 1000; gzip_types text/plain application/xml; gzip_disable "MSIE [1-6]\.";
HTTP Referer
Filter requests based on Referer header.
location /photos/ {
valid_referers none blocked
www.mydomain.com
mydomain.com;
if ($invalid_referer) {
return 403;
}
}
HTTP Limit Zone
Limit simultaneous connections from a client.
http {
limit_zone one $binary_remote_addr 10m;
server {
location /download/ {
limit_conn one 1;
}
}
}
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;
}
}
}
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;
}
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;
}
}
HTTP Proxy
Proxy to upstream servers.
location / {
proxy_pass http://localhost:8000;
proxy_set_header X-Real-IP $remote_addr;
}
Rewrite
Request rewriting using regular expressions.
location /en {
rewrite ^/en/(.*)$ /($1)?lang=en last;
}
User ID
Issue identifying cookies.
userid on; userid_name uid; userid_domain example.com; userid_path /; userid_expires 365d;
Optional HTTP modules
The following modules must be enabled at compile-time with the specified option to configure.
HTTP Addition
Append text to pages.
--with-http_addition_module
location / {
add_before_body /before_action;
add_after_body /after_action;
}
GeoIP
Creates variables with information from the MaxMind GeoIP binary files.
--with-http_geoip_module
Mail modules
Third-Party modules and patches
Please see the catalog of 3rd party modules.












