<!-- review: finished -->

<a id="http-split-clients"></a>

# Split Clients

该模块用于 A/B 测试、金丝雀发布或其他需要将一部分客户端路由到一个服务器或配置，同时将其余部分路由到其他地方的场景。

<a id="configuration-example-40"></a>

## 配置示例

```nginx
http {
    split_clients "${remote_addr}AAA" $variant {
                   0.5%               .one;
                   2.0%               .two;
                   *                  "";
    }

    server {
        location / {
            index index${variant}.html;
```

<a id="directives-43"></a>

## 指令

<a id="index-0"></a>

<a id="id3"></a>

### split_clients

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `split_clients` string $variable { ... }   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | —                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                       |

通过哈希 string 创建一个 $variable；
string 中的变量被替换，
替换结果被哈希，
然后将哈希值用于选择 $variable 的字符串值。

哈希函数使用
[MurmurHash2](https://en.wikipedia.org/wiki/MurmurHash#MurmurHash2)
（32 位），
其整个值范围
（0 到 4294967295）
按出现顺序映射到桶中；
百分比决定了桶的大小。
通配符 (`*`) 可以出现在最后；
不属于其他桶的哈希值会映射到其指定的值。

示例：

```nginx
split_clients "${remote_addr}AAA" $variant {
               0.5%               .one;
               2.0%               .two;
               *                  "";
}
```

在这里，替换 `$*remote_addr*AAA` 字符串后，
哈希值分布如下：

- 值从 0 到 21474835（0.5%）产生 `.one`；
- 值从 21474836 到 107374180（2%）产生 `.two`；
- 值从 107374181 到 4294967295（所有其他值）产生 `""`
  （空字符串）。
