# Ab testing

**URL:** <https://www.ruby-forum.com/t/ab-testing/205519>\
**Category:** NGINX\
**Created:** [April 8, 2011, 12:33am UTC](https://www.ruby-forum.com/t/ab-testing/205519 "2011-04-08T00:33:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [April 8, 2011, 12:33am UTC](https://www.ruby-forum.com/t/ab-testing/205519/1 "2011-04-08T00:33:50Z")

</div>

hi! first I wanted to say that nginx is a great product!  
I am trying to use it to route my traffic with several different rules.  
This  
way I can do ab testing.  
My rules use different inputs, like http headers and uri of the request.  
I am using right now the location block with regex. But when I need to  
do  
something more complex (like matching the query string and http\_method)  
I  
can’t find a way to do it as it seems like nginx doesn’t have a rich  
programming language, which is reasonable. But I am sure there are ways  
to  
do what I want, like:

location ~ /items.\* {  
if ($query\_string ~ ._&ids=._ && $request\_method = GET) {  
proxy\_pass pool\_a;  
}  
proxy\_pass pool\_b;  
}

this is just an example, my rules can get more complex. what would be  
the  
recommended way to address this?

thanks!

jonathan

---

<div class="post-metadata">

**Author:** ![johanatan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johanatan](https://www.ruby-forum.com/u/johanatan)\
**Post date:** [April 8, 2011, 1:42am UTC](https://www.ruby-forum.com/t/ab-testing/205519/2 "2011-04-08T01:42:28Z")

</div>

nginx doesn’t have a rich programming language :). if - it is only a new  
localtion :).

see this example:

([http://markmail.org/message/yv6x3z66x3a5jdv2](http://markmail.org/message/yv6x3z66x3a5jdv2))  
[http://markmail.org/message/yv6x3z66x3a5jdv2](http://markmail.org/message/yv6x3z66x3a5jdv2)  
([http://markmail.org/message/yv6x3z66x3a5jdv2](http://markmail.org/message/yv6x3z66x3a5jdv2))

Thu, 7 Apr 2011 19:33:25 -0300 письмо от Jonathan L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

hi! first I wanted to say that nginx is a great product!  
I am trying to use it to route my traffic with several different rules.  
This way I can do ab testing.  
My rules use different inputs, like http headers and uri of the request.  
I am using right now the location block with regex. But when I need to  
do something more complex (like matching the query string and  
http\_method) I can’t find a way to do it as it seems like nginx doesn’t  
have a rich programming language, which is reasonable. But I am sure  
there are ways to do what I want, like:

location ~ /items.\* {  
if ($query\_string ~ ._&ids=._ && $request\_method = GET) {  
proxy\_pass pool\_a;  
}  
proxy\_pass pool\_b;  
}

this is just an example, my rules can get more complex. what would be  
the recommended way to address this?

thanks!

jonathan

---

<div class="post-metadata">

**Author:** ![johanatan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johanatan](https://www.ruby-forum.com/u/johanatan)\
**Post date:** [April 8, 2011, 1:50am UTC](https://www.ruby-forum.com/t/ab-testing/205519/3 "2011-04-08T01:50:28Z")

</div>

so there is no way to do what I am trying to do?  
I see I could make rewrites. the problem with that is that it won’t be  
transparent to the application underneath.  
I know there is a lua module. maybe there is a way to do it with lua?

as I said, I just need to be able to match on headers and uri and decide  
to  
which upstream to pass the request.

---

<div class="post-metadata">

**Author:** ![johanatan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johanatan](https://www.ruby-forum.com/u/johanatan)\
**Post date:** [April 9, 2011, 4:04am UTC](https://www.ruby-forum.com/t/ab-testing/205519/4 "2011-04-09T04:04:23Z")

</div>

location ~ /items.\* {  
set $ok 1;  
if ($query\_string !~ ._&ids=._) {  
set $ok 0;  
}  
if ($request\_method != GET) {  
set $ok 0;  
}  
if ( $ok = 1 ) {  
proxy\_pass [http://mail.ru](http://mail.ru); ([http://mail.ru](http://mail.ru)😉  
}  
if ( $ok = 0 ) {  
proxy\_pass [http://google.ru](http://google.ru); ([http://google.ru](http://google.ru)😉  
}  
}

Thu, 7 Apr 2011 20:50:15 -0300 письмо от Jonathan L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

so there is no way to do what I am trying to do?  
I see I could make rewrites. the problem with that is that it won’t be  
transparent to the application underneath.  
I know there is a lua module. maybe there is a way to do it with lua?

as I said, I just need to be able to match on headers and uri and decide  
to which upstream to pass the request.

On Thu, Apr 7, 2011 at 8:42 PM, Ivan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
nginx doesn’t have a rich programming language :). if - it is only a new  
localtion :).

see this example:

[http://markmail.org/message/yv6x3z66x3a5jdv2](http://markmail.org/message/yv6x3z66x3a5jdv2)  
([http://markmail.org/message/yv6x3z66x3a5jdv2](http://markmail.org/message/yv6x3z66x3a5jdv2))

Thu, 7 Apr 2011 19:33:25 -0300 письмо от Jonathan L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

hi! first I wanted to say that nginx is a great product!  
I am trying to use it to route my traffic with several different rules.  
This way I can do ab testing.  
My rules use different inputs, like http headers and uri of the request.  
I am using right now the location block with regex. But when I need to  
do something more complex (like matching the query string and  
http\_method) I can’t find a way to do it as it seems like nginx doesn’t  
have a rich programming language, which is reasonable. But I am sure  
there are ways to do what I want, like:

location ~ /items.\* {  
if ($query\_string ~ ._&ids=._ && $request\_method = GET) {  
proxy\_pass pool\_a;  
}  
proxy\_pass pool\_b;  
}

this is just an example, my rules can get more complex. what would be  
the recommended way to address this?

thanks!

jonathan

* * *

nginx mailing list  
removed\_email\_address@domain.invalid  
[nginx Info Page](http://nginx.org/mailman/listinfo/nginx)  
([nginx Info Page](http://nginx.org/mailman/listinfo/nginx))

---

<div class="post-metadata">

**Author:** ![johanatan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johanatan](https://www.ruby-forum.com/u/johanatan)\
**Post date:** [April 18, 2011, 7:08am UTC](https://www.ruby-forum.com/t/ab-testing/205519/5 "2011-04-18T07:08:44Z")

</div>

On Fri, Apr 8, 2011 at 6:33 AM, Jonathan L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> hi! first I wanted to say that nginx is a great product!  
> I am trying to use it to route my traffic with several different rules. This  
> way I can do ab testing.  
> My rules use different inputs, like http headers and uri of the request.  
> I am using right now the location block with regex. But when I need to do  
> something more complex (like matching the query string and http\_method) I  
> can’t find a way to do it as it seems like nginx doesn’t have a rich  
> programming language, which is reasonable. But I am sure there are ways to  
> do what I want, like:

I’d recommend you use ngx\_lua’s rewrite\_by\_lua or access\_by\_lua  
directives to code up such complicated business logic. See

```
http://github.com/chaoslawful/lua-nginx-module

```

for details.

Cheers,  
-agentzh
