非常教程

Nginx参考手册

ngx_http_map_module

ngx_http_map_module

  • 示例配置
  • 指令
  • map
  • map_hash_bucket_size
  • map_hash_max_size

ngx_http_map_module模块创建值取决于其他变量值的变量。

示例配置

map $http_host $name {
    hostnames;

    default       0;

    example.com   1;
    *.example.com 1;
    example.org   2;
    *.example.org 2;
    .example.net  3;
    wap.*         4;
}

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

指令

句法:

map string $variable { ... }

默认:

语境:

HTTP

创建一个新变量,其值取决于第一个参数中指定的一个或多个源变量的值。

在版本0.9.0之前,只能在第一个参数中指定一个变量。由于变量仅在使用时才被评估,因此仅仅声明大量的map变量不会增加任何额外的成本来请求处理。

map块内的参数指定源值和结果值之间的映射。

源值被指定为字符串或正则表达式(0.9.6)。

字符串匹配忽略案件。

正则表达式应该从~用于区分大小写匹配的“ ~*”符号开始,或者从符号(1.0.4)开始用于不区分大小写的匹配。正则表达式可以包含命名和位置捕获,稍后可以将其用于其他指令以及结果变量。

如果源值与下面描述的特殊参数名称之一相匹配,则应该以“ \”符号为前缀。

结果值可以包含文本,变量(0.9.0)及其组合(1.11.0)。

以下特殊参数也受支持:

defaultvalue如果源值不匹配指定的变体,则设置结果值。如果default未指定,则默认结果值将为空字符串。hostnames表示源值可以是具有前缀或后缀掩码的主机名:

*.example.com 1;
example.*     1;

以下两条记录

example.com   1;
*.example.com 1;

可以合并:

.example.com  1;

这个参数应该在值列表之前指定。includefile包含一个包含值的文件。可以有几个内含物。volatile表示该变量不可缓存(1.11.7)。

如果源值匹配多个指定变体(例如,掩码和正则表达式匹配),则将按照以下优先级顺序选择第一个匹配变体:

  • 没有掩码的字符串值
  • 带有前缀掩码的最长字符串值,例如“ *.example.com
  • 带有后缀掩码的最长字符串值,例如“ mail.*
  • 首先匹配正则表达式(按照出现在配置文件中的顺序)
  • 默认值

句法:

map_hash_bucket_size大小;

默认:

map_hash_bucket_size 32 | 64 | 128;

语境:

HTTP

设置地图变量哈希表的桶大小。默认值取决于处理器的高速缓存行大小。设置散列表的细节在单独的文档中提供。

句法:

map_hash_max_size大小;

默认:

map_hash_max_size 2048;

语境:

HTTP

设置地图变量散列表的最大尺寸。 设置散列表的细节在单独的文档中提供。

ngx_http_map_module
Nginx

Nginx是一款轻量级的 Web 服务器/反向代理服务器及电子邮件代理服务器,可在 BSD-like 协议下发行。其特点是占有内存少,并发能力强。

主页 https://nginx.org/
源码 http://hg.nginx.org/nginx
发布版本 1.13.6

Nginx目录

1.指南 | Guides
2.核心 | Core
3.ngx_google_perftools_module
4.ngx_http_access_module
5.ngx_http_addition_module
6.ngx_http_api_module
7.ngx_http_auth_basic_module
8.ngx_http_auth_jwt_module
9.ngx_http_auth_request_module
10.ngx_http_autoindex_module
11.ngx_http_browser_module
12.ngx_http_charset_module
13.ngx_http_core_module
14.ngx_http_dav_module
15.ngx_http_empty_gif_module
16.ngx_http_f4f_module
17.ngx_http_fastcgi_module
18.ngx_http_flv_module
19.ngx_http_geoip_module
20.ngx_http_geo_module
21.ngx_http_gunzip_module
22.ngx_http_gzip_module
23.ngx_http_gzip_static_module
24.ngx_http_headers_module
25.ngx_http_hls_module
26.ngx_http_image_filter_module
27.ngx_http_index_module
28.ngx_http_js_module
29.ngx_http_keyval_module
30.ngx_http_limit_conn_module
31.ngx_http_limit_req_module
32.ngx_http_log_module
33.ngx_http_map_module
34.ngx_http_memcached_module
35.ngx_http_mirror_module
36.ngx_http_mp4_module
37.ngx_http_perl_module
38.ngx_http_proxy_module
39.ngx_http_random_index_module
40.ngx_http_realip_module
41.ngx_http_referer_module
42.ngx_http_rewrite_module
43.ngx_http_scgi_module
44.ngx_http_secure_link_module
45.ngx_http_session_log_module
46.ngx_http_slice_module
47.ngx_http_spdy_module
48.ngx_http_split_clients_module
49.ngx_http_ssi_module
50.ngx_http_ssl_module
51.ngx_http_status_module
52.ngx_http_stub_status_module
53.ngx_http_sub_module
54.ngx_http_upstream_conf_module
55.ngx_http_upstream_hc_module
56.ngx_http_upstream_module
57.ngx_http_userid_module
58.ngx_http_uwsgi_module
59.ngx_http_v2_module
60.ngx_http_xslt_module
61.ngx_mail_auth_http_module
62.ngx_mail_core_module
63.ngx_mail_imap_module
64.ngx_mail_pop3_module
65.ngx_mail_proxy_module
66.ngx_mail_smtp_module
67.ngx_mail_ssl_module
68.ngx_stream_access_module
69.ngx_stream_core_module
70.ngx_stream_geoip_module
71.ngx_stream_geo_module
72.ngx_stream_js_module
73.ngx_stream_limit_conn_module
74.ngx_stream_log_module
75.ngx_stream_map_module
76.ngx_stream_proxy_module
77.ngx_stream_realip_module
78.ngx_stream_return_module
79.ngx_stream_split_clients_module
80.ngx_stream_ssl_module
81.ngx_stream_ssl_preread_module
82.ngx_stream_upstream_hc_module
83.ngx_stream_upstream_module