Nginx Module Reference Manual: Map module (MAP)

Source: Internet
Author: User
Keywords Nginx map Module
Tags compiled configure create default default value different domain example

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.