How to have 10% of requests rewrite

Anton Yuzhaninov citrin at citrin.ru
Tue Feb 2 13:04:51 MSK 2010


kshaikh wrote:

> I have a proxy which runs at http://xs.to.  It caches http://f0.ultraxs.com.  I need it to rewrite to a JPG 10% of the time.
...
> Is there a good clean way to run an if statement and rewrite 10% of the requests ?

This can be done via embedded perl

example:

perl_set $random_rewrite_to '
sub { rand > 0.1 ? "url_90_percent" : "url_10_percent" }
';

server {

   ....

   location /some_location {
      rewrite ^ $random_rewrite_to;
   }


}

-- 
 Anton Yuzhaninov



More information about the nginx mailing list