One server with two rails applications

Hello all,

I have one machine and two ruby applications, app1 and app2. Currently, I have an Apache server and a mongrel server. Apache runs on port 80 and proxies to mongrel on port 3001, which runs app1. But I wish to run both applications on the one machine. There is documentation that suggests clustering. But each application will need it's own URL, http://localhost/app1 and http://localhost/app2. Can anyone direct me on how to do this?

Thanks,

j

John - you're gonna want to look into virtual hosts.

Virtual hosts allow you to serve multiple sites from one IP address.

Here's a sample server_one.com vhost. Sending server_one.com requests to a cluster of 4 mongrels- Duplicate it, and change for a second to answer on the same ip. Not the below may need some more params to work plus the correct mods installed.

<VirtualHost www.server_one.com:80>    ServerName www. server_one.com

   ServerAlias www. server_one.com server_one.com

   DocumentRoot /var/www/apps/server_one/current/public

   <Proxy balancer://server_one_cluster>      BalancerMember http://127.0.0.1:6000      BalancerMember http://127.0.0.1:6001      BalancerMember http://127.0.0.1:6002      BalancerMember http://127.0.0.1:6003    </Proxy>

</VirtualHost>

Jodi

But neither app1 nor app2 will have URLs like that by default.

How do you configure Rails to prepend "/app1" to every URL that it creates?

Try this guide for full setup of Apache (with virtual hosts) and a mongrel cluster. http://blog.codahale.com/2006/06/19/time-for-a-grown-up-server-rails-mongrel-apache-capistrano-and-you/

Helzer

> How do you configure Rails to prepend "/app1" to every URL that it > creates? > You could fix that with routing I think.

? Can you be more explicit?

Or you could go the virtual host way (my preference)

But that's not what the OP asked for.

And for future reference I'd also like to know if it's possible...

Both good info, thanks!

If you choose this approach you are, as far as I can gather, forced to change all your hrefs & forms in the applications to mimic this sort of set up. I.e application: test, controller: teams, action: list URL: http://localhost/test/teams/list But it is quite a job to rename all the URLs in the application.

Is there another way around this?

If you choose this approach you are, as far as I can gather, forced to change all your hrefs & forms in the applications to mimic this sort of set up. I.e application: test, controller: teams, action: list URL: http://localhost/test/teams/list But it is quite a job to rename all the URLs in the application.

Is there another way around this?

Setting the routes as I did should automatically prepend test/ to
urls generated from url_for (or the things that use it (form_tag/for,
link_to etc...); at least it did when I tried it.

Fred

I use this setup, just pass --prefix=/app1 or --prefix=/app2 into mongrel. The only changes you will need to make are image urls in your stylesheets.