You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by mraible <ma...@raibledesigns.com> on 2007/04/18 22:03:39 UTC

[users@httpd] Is it possible for Apache to randomly select different URLs to serve up?

Is it possible for Apache to randomly select different URLs to serve up?  For
example:

User1 -> http://my.domain.com/1
User2 -> http://my.domain.com/2
User3 -> http://my.domain.com/3

And after a certain point, start over again?  I'm not really looking for
random, ordered would work.

For more information, please read more below.

Thanks,

Matt

[More]

I have configured Apache with mod_jk and mod_rewrite to forward to different
applications deployed in Tomcat based on a parameter.  For example:

http://my.domain.com/?v=1 --> tomcat/webapps/app1
http://my.domain.com/?v=2 --> tomcat/webapps/app2

If this parameter is not in the URL, the default Tomcat application
(tomcat/webapps/ROOT) will be served up.

The reason I'm doing this for A/B Testing - so a new app can be deployed
with small changed and users will get routed to it. The reason for the "v"
parameter is to ensure users are routed to a particular app when they pass
URLs around to friends and such. In addition to a "v" parameter, I'm looking
for a "v" cookie and routing appropriately. 

This all works great and I'm happy with my current setup. If you need more
details, please see my blog entry[1] where I documented my experience.

For those users who come in w/o a "v" parameter or "v" cookie, I'd like to
evenly distribute them to the different version of the site. I'm not so
concerned about the "evenly" aspect, but I would like to send users to
different applications.  Is this something that's possible with Apache or
should I do this in the ROOT webapp in Tomcat?

[1] http://raibledesigns.com/rd/entry/mixing_apache_http_server_mod
-- 
View this message in context: http://www.nabble.com/Is-it-possible-for-Apache-to-randomly-select-different-URLs-to-serve-up--tf3603013.html#a10065662
Sent from the Apache HTTP Server - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Is it possible for Apache to randomly select different URLs to serve up?

Posted by Nick Kew <ni...@webthing.com>.
On Wed, 18 Apr 2007 13:03:39 -0700 (PDT)
mraible <ma...@raibledesigns.com> wrote:

> 
> Is it possible for Apache to randomly select different URLs 

The browser requests a URL.  What apache serves at that URL
is your business and can of course be random.

> User1 -> http://my.domain.com/1
> User2 -> http://my.domain.com/2
> User3 -> http://my.domain.com/3

Many ways to do that.  For example, RewriteMap.

> For those users who come in w/o a "v" parameter or "v" cookie, I'd
> like to evenly distribute them to the different version of the site.

That's called load balancing.  You want mod_proxy_balancer.

-- 
Nick Kew

Application Development with Apache - the Apache Modules Book
http://www.apachetutor.org/

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Is it possible for Apache to randomly select different URLs to serve up?

Posted by mraible <ma...@raibledesigns.com>.
Figured it out - here's the solution I used:

1. Just above the JkMount line in httpd.conf, add the following lines to
turn on logging and setup a map of applications. Don't forget to replace X
with the current version number (i.e. 2.2.4).

RewriteLogLevel 3
RewriteLog c:/Tools/apache-X/logs/rewrite.log
RewriteMap apps rnd:c:/Tools/apache-X/conf/applications.txt

2. Create a conf/applications.txt file and add the following line to it:

sites app|app1|app2

3. Add a RewriteRule in <Directory "/opt/local/apache2/htdocs"> to use the
map:

    # http://domain --> http://domain/app|app1|app2 (random application in
Tomcat)
    RewriteRule     ^(.*)               /${apps:sites}/$1 [L]

4. Restart Apache, delete all cookies and open http://localhost. Refresh
your browser a number of times and watch yourself get routed to the
different applications randomly.

Thanks for all the help on this thread.

Matt


mraible wrote:
> 
> It seems there's two ways to do this and I can't get either one to work. 
> 
> #1: Using a perl script:
> 
> RewriteMap router prg:/opt/local/apache2/conf/router.pl
> RewriteRule ^(.*)$ ${router} [R,L]
> 
> router.pl:
> 
> #!/usr/bin/perl
> my $range = 3;
> my $random_number = int(rand($range));
> 
> print "/?v=" . $random_number;
> 
> Going to "http://localhost" in my browser results in:
> 
> http://localhost/$%7brouter%7d
> 
> #2 Using rnd
> 
> RewriteMap servers rnd:/opt/local/apache2/conf/servers.map
> RewriteRule ^(.*)$ ${servers} [R,L]
> 
> servers.map:
> /?v=0|/?v=1|/?v=2
> 
> Going to "http://localhost" in my browser results in:
> 
> http://localhost/$%7bservers%7d
> 
> All my mod_rewrite settings follow the 2nd </Directory> in my httpd.conf.
> This is the one that starts with:
> 
> <Directory "/opt/local/apache2/htdocs">
> 
> I'm using Apache 2.2.4 on OS X.
> 
> I have the following just before the RewriteMap lines:
> 
> RewriteEngine On
> RewriteLog "/opt/local/apache2/logs/rewrite.log"
> 
> For some reason rewrite.log is created, but nothing is in it.
> 
> Thanks in advance for any help,
> 
> Matt
>  
> 
> Joshua Slive-2 wrote:
>> 
>> On 4/18/07, Serge Dubrouski <se...@gmail.com> wrote:
>>> A simple JavaScript serving as a main page and redirecting users to a
>>> random URI from your site would do. I don't think that it would be
>>> possible to do on Apache configuration level
>>>
>>> On 4/18/07, mraible <ma...@raibledesigns.com> wrote:
>>> >
>>> > Is it possible for Apache to randomly select different URLs to serve
>>> up?  For
>>> > example:
>>> >
>>> > User1 -> http://my.domain.com/1
>>> > User2 -> http://my.domain.com/2
>>> > User3 -> http://my.domain.com/3
>> 
>> Actually, mod_rewrite can do it using a rnd: RewriteMap.
>> 
>> Joshua.
>> 
>> ---------------------------------------------------------------------
>> The official User-To-User support forum of the Apache HTTP Server
>> Project.
>> See <URL:http://httpd.apache.org/userslist.html> for more info.
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Is-it-possible-for-Apache-to-randomly-select-different-URLs-to-serve-up--tf3603013.html#a10110297
Sent from the Apache HTTP Server - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Is it possible for Apache to randomly select different URLs to serve up?

Posted by mraible <ma...@raibledesigns.com>.
It seems there's two ways to do this and I can't get either one to work. 

#1: Using a perl script:

RewriteMap router prg:/opt/local/apache2/conf/router.pl
RewriteRule ^(.*)$ ${router} [R,L]

router.pl:

#!/usr/bin/perl
my $range = 3;
my $random_number = int(rand($range));

print "/?v=" . $random_number;

Going to "http://localhost" in my browser results in:

http://localhost/$%7brouter%7d

#2 Using rnd

RewriteMap servers rnd:/opt/local/apache2/conf/servers.map
RewriteRule ^(.*)$ ${servers} [R,L]

servers.map:
/?v=0|/?v=1|/?v=2

Going to "http://localhost" in my browser results in:

http://localhost/$%7bservers%7d

All my mod_rewrite settings follow the 2nd </Directory> in my httpd.conf.
This is the one that starts with:

<Directory "/opt/local/apache2/htdocs">

I'm using Apache 2.2.4 on OS X.

I have the following just before the RewriteMap lines:

RewriteEngine On
RewriteLog "/opt/local/apache2/logs/rewrite.log"

For some reason rewrite.log is created, but nothing is in it.

Thanks in advance for any help,

Matt
 

Joshua Slive-2 wrote:
> 
> On 4/18/07, Serge Dubrouski <se...@gmail.com> wrote:
>> A simple JavaScript serving as a main page and redirecting users to a
>> random URI from your site would do. I don't think that it would be
>> possible to do on Apache configuration level
>>
>> On 4/18/07, mraible <ma...@raibledesigns.com> wrote:
>> >
>> > Is it possible for Apache to randomly select different URLs to serve
>> up?  For
>> > example:
>> >
>> > User1 -> http://my.domain.com/1
>> > User2 -> http://my.domain.com/2
>> > User3 -> http://my.domain.com/3
> 
> Actually, mod_rewrite can do it using a rnd: RewriteMap.
> 
> Joshua.
> 
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Is-it-possible-for-Apache-to-randomly-select-different-URLs-to-serve-up--tf3603013.html#a10089394
Sent from the Apache HTTP Server - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Is it possible for Apache to randomly select different URLs to serve up?

Posted by Joshua Slive <jo...@slive.ca>.
On 4/18/07, Serge Dubrouski <se...@gmail.com> wrote:
> A simple JavaScript serving as a main page and redirecting users to a
> random URI from your site would do. I don't think that it would be
> possible to do on Apache configuration level
>
> On 4/18/07, mraible <ma...@raibledesigns.com> wrote:
> >
> > Is it possible for Apache to randomly select different URLs to serve up?  For
> > example:
> >
> > User1 -> http://my.domain.com/1
> > User2 -> http://my.domain.com/2
> > User3 -> http://my.domain.com/3

Actually, mod_rewrite can do it using a rnd: RewriteMap.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Is it possible for Apache to randomly select different URLs to serve up?

Posted by Serge Dubrouski <se...@gmail.com>.
A simple JavaScript serving as a main page and redirecting users to a
random URI from your site would do. I don't think that it would be
possible to do on Apache configuration level

On 4/18/07, mraible <ma...@raibledesigns.com> wrote:
>
> Is it possible for Apache to randomly select different URLs to serve up?  For
> example:
>
> User1 -> http://my.domain.com/1
> User2 -> http://my.domain.com/2
> User3 -> http://my.domain.com/3
>
> And after a certain point, start over again?  I'm not really looking for
> random, ordered would work.
>
> For more information, please read more below.
>
> Thanks,
>
> Matt
>
> [More]
>
> I have configured Apache with mod_jk and mod_rewrite to forward to different
> applications deployed in Tomcat based on a parameter.  For example:
>
> http://my.domain.com/?v=1 --> tomcat/webapps/app1
> http://my.domain.com/?v=2 --> tomcat/webapps/app2
>
> If this parameter is not in the URL, the default Tomcat application
> (tomcat/webapps/ROOT) will be served up.
>
> The reason I'm doing this for A/B Testing - so a new app can be deployed
> with small changed and users will get routed to it. The reason for the "v"
> parameter is to ensure users are routed to a particular app when they pass
> URLs around to friends and such. In addition to a "v" parameter, I'm looking
> for a "v" cookie and routing appropriately.
>
> This all works great and I'm happy with my current setup. If you need more
> details, please see my blog entry[1] where I documented my experience.
>
> For those users who come in w/o a "v" parameter or "v" cookie, I'd like to
> evenly distribute them to the different version of the site. I'm not so
> concerned about the "evenly" aspect, but I would like to send users to
> different applications.  Is this something that's possible with Apache or
> should I do this in the ROOT webapp in Tomcat?
>
> [1] http://raibledesigns.com/rd/entry/mixing_apache_http_server_mod
> --
> View this message in context: http://www.nabble.com/Is-it-possible-for-Apache-to-randomly-select-different-URLs-to-serve-up--tf3603013.html#a10065662
> Sent from the Apache HTTP Server - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org