Nginx中文文档
DocsHome
  • 贡献导引
  • 介绍
    • 安装 nginx
    • 从源码构建 nginx
    • 初学者指南
    • 管理指南
    • 控制 nginx
    • 连接处理方式
    • 设置哈希
    • 调试日志
    • 记录日志到 syslog
    • 配置文件度量单位
    • 命令行参数
    • Windows 下的 nginx
    • QUIC 和 HTTP/3 支持
    • nginx 如何处理请求
    • 服务器名称
    • 使用 nginx 作为 HTTP 负载均衡器
    • 配置 HTTPS 服务器
    • nginx 如何处理 TCP/UDP 会话
    • 关于 nginScript
  • 其他
    • Linux 软件包
  • How-To
    • 在 Win32 平台上使用 Visual C 构建 nginx
    • 设置 Amazon EC2 的 Nginx Plus 环境
    • 使用 DTrace pid 提供程序调试 nginx
    • 转换重写规则
    • WebSocket 代理
  • 开发
    • 贡献指南
    • 开发指南
  • 模块参考
  • 核心功能
    • HTTP
      • ngx_http_core_module
      • ngx_http_access_module
      • ngx_http_addition_module
      • ngx_http_api_module
      • ngx_http_auth_basic_module
      • ngx_http_auth_jwt_module
      • ngx_http_auth_request_module
      • ngx_http_autoindex_module
      • ngx_http_browser_module
      • ngx_http_charset_module
      • ngx_http_dav_module
      • ngx_http_empty_gif_module
      • ngx_http_f4f_module
      • ngx_http_fastcgi_module
      • ngx_http_flv_module
      • ngx_http_geo_module
      • ngx_http_geoip_module
      • ngx_http_grpc_module
      • ngx_http_gunzip_module
      • ngx_http_gzip_module
      • ngx_http_gzip_static_module
      • ngx_http_headers_module
      • ngx_http_hls_module
      • ngx_http_image_filter_module
      • ngx_http_index_module
      • ngx_http_js_module
      • ngx_http_keyval_module
      • ngx_http_limit_conn_module
      • ngx_http_limit_req_module
      • ngx_http_log_module
      • ngx_http_map_module
      • ngx_http_memcached_module
      • ngx_http_mirror_module
      • ngx_http_mp4_module
      • ngx_http_perl_module
      • ngx_http_proxy_module
      • ngx_http_random_index_module
      • ngx_http_realip_module
      • ngx_http_referer_module
      • ngx_http_rewrite_module
      • ngx_http_scgi_module
      • ngx_http_secure_link_module
      • ngx_http_session_log_module
      • ngx_http_slice_module
      • ngx_http_spdy_module(过时)
      • ngx_http_split_clients_module
      • ngx_http_ssi_module
      • ngx_http_ssl_module
      • ngx_http_status_module(过时)
      • ngx_http_stub_status_module
      • ngx_http_sub_module
      • ngx_http_upstream_module
      • ngx_http_upstream_conf_module
      • ngx_http_upstream_hc_module
      • ngx_http_userid_module
      • ngx_http_uwsgi_module
      • ngx_http_v2_module
      • ngx_http_xslt_module
    • Mail
      • ngx_mail_core_module
      • ngx_mail_auth_http_module
      • ngx_mail_proxy_module
      • ngx_mail_ssl_module
      • ngx_mail_imap_module
      • ngx_mail_pop3_module
      • ngx_mail_smtp_module
    • Stream
      • ngx_stream_core_module
      • ngx_stream_access_module
      • ngx_stream_geo_module
      • ngx_stream_geoip_module
      • ngx_stream_js_module
      • ngx_stream_keyval_module
      • ngx_stream_limit_conn_module
      • ngx_stream_log_module
      • ngx_stream_map_module
      • ngx_stream_proxy_module
      • ngx_stream_realip_module
      • ngx_stream_return_module
      • ngx_stream_split_clients_module
      • ngx_stream_ssl_module
      • ngx_stream_ssl_preread_module
      • ngx_stream_upstream_module
      • ngx_stream_upstream_hc_module
      • ngx_stream_zone_sync_module
    • 其他
      • ngx_google_perftools_module
由 GitBook 提供支持
在本页
  • 示例配置
  • 指令
  • map
  • map_hash_bucket_size
  • map_hash_max_size
  • 原文档
  1. 核心功能
  2. HTTP

ngx_http_map_module

上一页ngx_http_log_module下一页ngx_http_memcached_module

最后更新于5年前

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

-

说明

语法

map string $variable { ... };

默认

——

上下文

http

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

在 0.9.0 版本之前,只能在第一个参数中指定一个变量。

由于只有在使用变量时才计算变量的值,因此仅仅声明大量的 map 变量也不会增加额外请求处理负荷。

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

源值可以是字符串或正则表达式(0.9.6)。

字符串匹配将忽略大小写。

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

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

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

还支持以下特殊参数:

  • default

    如果源值不匹配指定变体,则设置结果值。如果未指定 default,则默认结果值为空字符串。

  • hostname

    表示源值可以是具有前缀或后缀掩码的主机名:

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

    以下两条记录

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

    可以合并:

      .example.com 1;

    这个参数应该在值列表之前指定。

  • include file

    包含一个包含值的文件。可以有多个包含。

  • volatile

    表示该变量不可缓存(1.11.7)

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

  1. 没有掩码的字符串值

  2. 带有前缀掩码的最长字符串值,例如 *.example.com

  3. 带有后缀掩码的最长字符串值,例如 mail.*

  4. 首先匹配正则表达式(按照在配置文件中出现的顺序)

  5. 默认值

map_hash_bucket_size

-

说明

语法

map_hash_bucket_size size;

默认

map_hash_bucket_size 32|64|128;

上下文

http

map_hash_max_size

-

说明

语法

map_hash_max_size size;

默认

map_hash_max_size 2048;

上下文

http

原文档

设置 变量哈希表的桶大小。默认值取决于处理器的缓存行大小。设置哈希表的详细内容可在单独的中找到。

设置 变量哈希表的最大大小(size)。设置哈熟表的详细内容可在单独的中找到。

http://nginx.org/en/docs/http/ngx_http_map_module.html
指令
map
map_hash_bucket_size
map_hash_max_size
文档
map
文档
map