How to have 10% of requests rewrite

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

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 Y.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs