惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
D
Docker
J
Java Code Geeks
L
LangChain Blog
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
T
Tailwind CSS Blog
M
MIT News - Artificial intelligence
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
腾讯CDC
罗磊的独立博客
U
Unit 42
爱范儿
爱范儿
Vercel News
Vercel News
MyScale Blog
MyScale Blog

烧饼博客

烧饼论坛正式开业 - 烧饼博客 博客大联盟:一个给独立博客的收录与聚合站 - 烧饼博客 回归初心,文字为王 - 烧饼博客 Ubuntu 24.04 Noble 升级 Ubuntu 26.04 Resolute WSL 2 使用 Docker 桥接模式网络访问 HTTPS 超时的解决方法 Debian / Ubuntu 下使用 nginx-acme 自动签发并配置 SSL 证书 使用 acme.sh 配置 Let's Encrypt 签发的 IP 地址 SSL 证书 RDAP.SS - 基于 RDAP 协议的 Whois 查询网站 Debian 使用 extrepo 配置第三方软件源 升级 Debian 后 GitLab PostgreSQL 无法启动的解决方法 Debian 12 Bookworm 升级 Debian 13 Trixie Ubuntu 22.04 Jammy 升级 Ubuntu 24.04 Noble Docker 安装 FreshRSS 教程 Debian / Ubuntu 开启 SSH 的 RSA Key 登录 - 烧饼博客 Debian 11 Bullseye 升级 Debian 12 Bookworm - 烧饼博客 Debian / Ubuntu 下使用 HTTP/3 协议的 Nginx QUIC - 烧饼博客 Debian / Ubuntu 使用 xcaddy 自定义编译 Caddy - 烧饼博客 Debian / Ubuntu 安装 Caddy - 烧饼博客 Debian / Ubuntu 手工添加 Swap 分区 - 烧饼博客 KDE Plasma 关闭单击打开文件或文件夹 - 烧饼博客 Firefox 指定特定网站关闭所有扩展 - 烧饼博客 Docker 安装 Shlink 自建短网址 Debian 安装 Nextcloud 服务端 Debian / Ubuntu 安装 PowerDNS 和 PowerDNS-Admin 自建权威 DNS 教程 - 烧饼博客 Debian 双栈网络时开启 IPv4 优先 Debian / Ubuntu 安装 Docker 以及 Docker Compose 教程 - 烧饼博客 SM.MS - 收费图床服务 - 烧饼博客 Debian / Ubuntu 使用源安装 LAMP 教程 Debian / Ubuntu 使用源安装 LEMP 教程
Nginx 使用 split_clients 进行简易 A/B 测试 - 烧饼博客
Showfom · 2022-07-03 · via 烧饼博客

本文将介绍在 Nginx 配置简易 A/B 测试的姿势。

#背景前提

有时候我们需要简单的做一些 A/B 测试,并不需要复杂的判断条件,这时候我们可以用到 Nginx 的 ngx_http_split_clients_module 模块。

#安装 ngx_http_split_clients_module 模块

一般来说这个模块已经自带,如果没有的话推荐安装我们打包的 N.WTF

#配置 Nginx

这里举例,我们想要 20% 的用户跳转到网址 https://example.com/30% 的用户跳转到网址 https://example.org/,剩下的跳转到网址 https://examle.edu/

上述例子中,按照访客请求的 IP 地址 加上 AAA 字符串 会使用 MurmurHash2 转换成数字,如果得出的数字在前 20%,那么 $variant 值为 https://example.com/,相应的在中间 30% 区间的值为 https://example.org/,其他的为 https://example.edu/

然后我们找两台不同 IP 的机器进行测试:

机器 A:

机器 B:

然后就可以有更灵活的用法,比如指定不同的目录:

指定不同的首页:

读者可以举一反三,这个比较简易的 A/B 测试就完成啦~