These modules are all compiled into Nginx by default unless a module is manually specified to be excluded in configure.
This module allows you to categorize or simultaneously map multiple values to multiple different values and store them in a variable, and the map instruction is used to create variables, but only when the variable is accepted, the view mapping operation is performed, and the module does not have a performance flaw in processing requests that do not have reference variables.
The following example:
Map $http _host $name {hostnames; default 0; example.com 1; *.example.com 1; test.com 2; *.test.com 2;. site.com 3;}
A typical example of using maps is to replace a/location or redirect that contains many servers:
Map $uri $new {default http://www.domain.com/home/;/aa http://aa.domain.com/;/bb http://bb.domain.com/; ^/cc/. p<suffix>.*) $ http://cc.domain.com/$suffix; /john http://my.domain.com/users/john/;
Instructions
Map
Syntax: Map $var 1 $var 2 {...}
Default value: None
Working with Fields: HTTP
Map is a mapping table set for a variable.
The mapping table consists of two columns, matching patterns and corresponding values, matching patterns can be a simple string or regular expression, using regular expressions (' ~ ')
Map $uri $myvalue {/aa/mapped_aa ~^/aa/(? <suffix>.*) $/mapped_bb/$suffix;}
If you have a string that begins with a wave number, but it is not a regular expression, you can use a backslash (' \ '):
Map $http _referer $myvalue {Mozilla 1234; \~mozilla 5678;}
The map directive has three specified parameters:
Default-Specifies the defaults that will be used if no matching results are available. Hostnames-Allows simple query matching of values similar to host names, and the following section of the first point is used as the exact hostname. For example: *.example.com 1;
Instead of writing two:
example.com 1;*.example.com 1;
You can write a single:
. example.com 1; Include-contains a file that contains a mapped value that can contain multiple.
Map_hash_max_size
Syntax: map_hash_max_size number
Default value: Map_hash_max_size 2048
Working with Fields: HTTP
This instruction sets the maximum number of hash tables corresponding to the mapping table, and more information can be referred to nginx partial optimizations.
Map_hash_bucket_size
Syntax: map_hash_bucket_size n
Default value: Map_hash_bucket_size 32/64/128
Working with Fields: HTTP
This instruction specifies the maximum value of a variable in a map table in the hash table, depending on the processor's cache, and more information can be referred to nginx partial optimizations.