Nginx map模块

L77

 

Syntax: map string $variable { ... }
Default:
Context: http

map 指令 

curl -H 'aaaa:4444444' -H 'Host:map.taohui.org.cn'  http://192.168.0.51:10001
map $http_host $name {
    hostnames;

    default       0;

    ~map.taow+.org.cn 1;
    *.taohui.org.cn   2;
    map.taohui.tech   3;
    map.taohui.*    4;
}

map $http_user_agent $mobile {
    default       0;
    "~Opera Mini" 1;
}

server {
    listen 10001;
    default_type text/plain;
    location /{
        return 200 '$name:$mobile
';
    }
}

类似编程语言的switch case 

map $http_user_agent $mobile {#这个含义就是 当$http_user_agent 值 = "~Opera Mini"  那么我们就将 $mobile值设置为 1 否则就设置为 0
    default       0;
    "~Opera Mini" 1;
}
Syntax: map_hash_bucket_size size;
Default:
map_hash_bucket_size 32|64|128;
Context: http
Syntax: map_hash_max_size size;
Default:
map_hash_max_size 2048;
Context: http
原文地址:https://www.cnblogs.com/jackey2015/p/10396898.html