ngx_http_map_module

"ngx_http_map_module" allows to classify, or map a set of values into a different set of values and store the result in a variable.

Example:

map  $http_host  $name  {
    hostnames;

    default          0;

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

One use for this would be to use a mapping in place of writing lots of server/location directives or redirects:

# create the following redirects: 
# http://www.domain.com/aa -> http://aa.domain.com/ 
# http://www.domain.com/bb -> http://bb.domain.com/ 
# http://www.domain.com/john -> http://my.domain.com/users/john/ 
# everything else -> http://www.domain.com/home/ 

map $uri $new {
    default        http://www.domain.com/home/;

    /aa            http://aa.domain.com/;
    /bb            http://bb.domain.com/;
    /john          http://my.domain.com/users/john/;
}

server {
    server_name   www.domain.com;
    rewrite  ^    $new   redirect;
}

Directives

map

syntax: map $var1 $var2 { ... }

default: none

context: http

map defines the mapping table which will be used to set a variable. There are three different type of maps:

map_hash_max_size

syntax: map_hash_max_size number

default: map_hash_max_size 2048

context: http

The directive sets the maximum size of a hash table to hold the variable map. For more details see the descriptions of hash settings Optimization section.

map_hash_bucket_size

syntax: map_hash_bucket_size n

default: map_hash_bucket_size 32/64/128

context: http

The directive sets the maximum size in a hash table to map variables. The default value depends on the size of the cache line processor. More see in the descriptions of hash settings in the Optimization section.

References

Original Documentation

NginxHttpMapModule (last edited 2007-11-21 09:24:42 by CliffWells)