nginx AB路由与反向代理

时间:2020-06-17 23:30:05

标签: nginx

我正在为我的团队设置Unbounce(着陆页CMS),我想用当前的自定义构建着陆页AB测试由该服务创建的页面。我的服务器使用nginx,因此我可以在那里进行所有路由。

我可以使用此位置路由将目标网页访问量的100%取消退回-这有效:

location ~ ^/landing-page-path/(.*)$ {
   proxy_pass   http://unbouncepages.com/landing-page-test/$1;
   proxy_http_version 1.1;
   proxy_set_header Connection "";
   proxy_ssl_server_name on;
   proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
   resolver xxx.xxx.xxx.xxx ipv6=off;
}

我尝试使用here描述的方法添加AB路由:

http {
  split_clients "${args}" $unbounce {
               50%               on;
               *                 off;
  }

  server {
        listen 80;
        server_name _;
        keepalive_timeout 5;
        underscores_in_headers on;
        large_client_header_buffers 4 16k;

    location ~ ^/landing-page-path/(.*)$ {
        if ($unbounce = "on") {
            proxy_pass   http://unbouncepages.com/landing-page-test/$1;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            proxy_ssl_server_name on;
            proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
            resolver xxx.xxx.xxx.xxx ipv6=off;
        }
    }
}

但是当我部署此配置时,我的服务器仅返回502,我看到此nginx错误:

[emerg] 1#1: "proxy_http_version" directive is not allowed here in /etc/nginx/conf.d/default.conf:18

似乎我不能将反向代理放在条件块中?如果是这样,是否还有其他方法可以像这样设置AB路由,其中​​一半时间将请求反向代理到外部URL,一半时间将其正常处理?

0 个答案:

没有答案