Forum: NGINX How to have 10% of requests rewrite

Posted by kshaikh (Guest)
on 2010-02-02 06:36
(Received via mailing list)
Guys,

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.

I did this with upstream backend, but the issue was that the disk i/o 
really shot up doing that.

Is there a good clean way to run an if statement and rewrite 10% of the 
requests ?

Khalid

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,49143,49143#msg-49143
Posted by Anton Yuzhaninov (Guest)
on 2010-02-02 11:05
(Received via mailing list)
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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.