对于给定的URL和User-Agent标题,是否有办法在Nginx中返回20%的不同页面(用于A / B测试)?
答案 0 :(得分:3)
答案 1 :(得分:1)
使用loadbalance功能,
http {
upstream myproject {
server 127.0.0.1:8000 weight=4;
server 127.0.0.1:8001;
}
server {
listen 80;
server_name www.domain.com;
location / {
proxy_pass http://myproject;
}
}
server {
listen 8000;
location / {
root /var/www/A;
}
}
server {
listen 8001;
location / {
root /var/www/B;
}
}
}
不太好看,但也许有效:)
答案 2 :(得分:0)
可以在配置中使用 split_clients 模块
http {
upstream myproject1 {
server 127.0.0.1:8000;
}
upstream myproject2 {
server 127.0.0.1:8001;
}
split_clients $remote_addr $upstream {
25% myproject2;
* myproject1;
}
server {
listen 80;
server_name www.domain.com;
location / {
proxy_pass http://$upstream;
}
}
}