Basic nginx Modules

nginx has several modules that provide all the functionality. Unlike with Apache DSO modules, nginx modules are compile-time only options. This means that there is currently no way to load or unload modules on-demand.

We’ll go over the “standard” modules, and list the ./configure directive to disable them. For the more common ones we’ll list a usage example, as the more complex modules would fall far beyond the scope of this article.

Module: access
Control access based on IP address
Disable: –without-http_access_module
Example:

location / {
	allow 98.132.201.14;
	deny all;
}

Module: auth basic
”Basic” HTTP authentication
Disable: –without-http_auth_basic_module
Example: I already have a nice tutorial on this

Module: auto index
Automatically generate directory listings
Disable: –without-http_autoindex_module
Example:

location /downloads {
	autoindex on;
}

Module: browser
Interpret “User-Agent:” header
Disable: –without-http_browser_module

Module: charset
Recode document character sets on the fly
Disable: –without-http_charset_module
Example:

include conf/win-utf;
charset utf-8;
source_charset windows-1252;

Module: empty gif
Serves a 1×1 transparent GIF, saves processing time on various CSS tricks that use the 1 pixel image trick.
Disable: –without-http_empty_gif_module
Example:

location = /images/1x1.gif {
	empty_gif;
}

Module: fastcgi
Allows FastCGI interraction, required for PHP processing, among other things.
Disable: –without-http_fastcgi_module
Example:

location / {
	fastcgi_pass  localhost:9000;
	fastcgi_index index.php;
}

Module: geo
Sets variables using key/value pairs of IP addresses and countries.
Disable: –without-http_geo_module

Module: gzip
Enables gzip compression of outbound data.
Disable: –without-http_gzip_module
Example:

gzip on;

Module: headers
Allows you to set various HTTP response headers
Disable: Can’t, it is a part of the HTTP core.

expires max; #sets the Expires: header to the maximum possible time, to improve client side caching

Module: index
Allows you to set which file is the directory index.
Disable: Can’t, it is a part of the HTTP core.

index index.htm index.html index.php index.shtml;

Module: limit requests
Limits HTTP connections based on frequency of connection.
Disable: –without-http_limit_req_module

http {
	limit_req_zone $binary_remote_addr zone=one:10m rate=3r/s;

	location /download {
		limit_req zone=somezone burst=10;
	}
}

Module: limit conn
Limits HTTP connections based on variables.
Disable: –without-http_limit_conn_module

http {
	limit_conn_zone $binary_remote_addr zone=addr:30m;

	location /download {
		limit_conn addr 3;
	}
}

Module: log
Allows you to customize the log output.
Disable: Can’t, it is a part of the core.

Module: map
Sets configuration values based on arbitrary key/value pairs.
Disable: –without-http_map_module

Module: memcached
Allows nginx to serve files out of a memcached cache.
Disable: –without-http_memcached_module

Module: proxy
Proxies connection to upstream servers.
Disable: –without-http_proxy_module
Example: See our article on nginx load balancing [Editor: link to the nginx load balancing article]

Module: referer
Filters requests based on the HTTP “referrer” header. Uses regular expressions, but requires an if statement.
Disable: –without-http_referer_module

valid_referers none blocked server_names
	*.somesiteyoulike.com example.* www.somesiteyoulike.org/some/path
	 ~.google.;

if ($invalid_referer) { #if anybody else, then...
	return 403; #block them!
}

Module: rewrite
Rewrites requests using regular expressions.
Disable: –without-http_rewrite_module

if ($http_user_agent ~ Mozilla) {
	rewrite ^(.*)$ /mozilla/$1 break; #rewrites the URL 
}

if ($invalid_referer) {
	return 403; #returning an error code uses this module
}

Module: scgi
Support for the SCGI protocol.
Disable: –without-http_scgi_module

Module: split clients
Splits clients based on various conditions.
Disable: –without-http_split_clients_module

Module: ssi
Allows for Server Side Includes.
Disable: –without-http_ssi_module
Example:

location / {
	ssi on;
}

Module: upstream
Required for load-balancing and forward proxying.
Disable: Can’t, it is a part of the proxy module
Example: See our article on nginx load balancing [Editor: link to the nginx load balancing article]

Module: upstream ip hash
Allows load balancing based on a hash of the IP address (back end stickyness)
Disable: –without-http_upstream_ip_hash_module
Example: See our article on nginx load balancing [Editor: link to the nginx load balancing article]

Module: user id
User identifying cookies. Used for advanced load balancing and caching setups.
Disable: –without-http_userid_module

Module: uwsgi
Support for the uWSGI protocol.
Disable: –without-http_uwsgi_module