# VirtualHost like in the Apache-PHP world

**URL:** <https://www.ruby-forum.com/t/virtualhost-like-in-the-apache-php-world/185704>\
**Category:** Mongrel\
**Created:** [March 24, 2010, 8:36pm UTC](https://www.ruby-forum.com/t/virtualhost-like-in-the-apache-php-world/185704 "2010-03-24T20:36:18Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nagy\_TamSSSSs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/5f9b8f/32.png) [@Nagy\_TamSSSSs](https://www.ruby-forum.com/u/Nagy_TamSSSSs)\
**Post date:** [March 24, 2010, 8:36pm UTC](https://www.ruby-forum.com/t/virtualhost-like-in-the-apache-php-world/185704/1 "2010-03-24T20:36:18Z")

</div>

How to make virtual hosts in mongrel?

::how to serve example1.tld, example2.tld, … exampleN.tld's  
different ruby apps?

thanks in advence  
frikazojd.

[\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
ÃšjdonsÃ¡g!  
MegÃ©rkezett a RIGHT GUARD fÃ©rfi testÃ¡polÃ¡si termÃ©kcsalÃ¡d! Most 25%  
kedvezmÃ©nnyel!  
AkÃ¡r 48 Ã³rÃ¡s hatÃ¡sos vÃ©delem a testszag ellen!  
](http://ad.adverticum.net/b/cl,1,73468,1598288,1592431/click.prm)

---

<div class="post-metadata">

**Author:** ![Nagy\_TamSSSSs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/5f9b8f/32.png) [@Nagy\_TamSSSSs](https://www.ruby-forum.com/u/Nagy_TamSSSSs)\
**Post date:** [March 24, 2010, 9:38pm UTC](https://www.ruby-forum.com/t/virtualhost-like-in-the-apache-php-world/185704/2 "2010-03-24T21:38:20Z")

</div>

You do it all in Apache. Typical way to deploy mongrel is fronted with  
an Apache reverse proxy. You need to set up everything in Apache, and  
have the right requests proxied to the right mongrel. It’s all about  
apache, no config in Mongrel.

You may also want to consider mod\_rails/passenger instead of mongrel, it  
seems to be more popular these days for Rails deployment, and you may  
find it easier to set up the way you want.

Jonathan

---

<div class="post-metadata">

**Author:** ![Nagy\_TamSSSSs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/5f9b8f/32.png) [@Nagy\_TamSSSSs](https://www.ruby-forum.com/u/Nagy_TamSSSSs)\
**Post date:** [March 24, 2010, 11:45pm UTC](https://www.ruby-forum.com/t/virtualhost-like-in-the-apache-php-world/185704/3 "2010-03-24T23:45:56Z")

</div>

2010/3/24 Nagy Tamás [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> but i’d like to try out Mongrel..  
> so, I set the apache with mod\_proxy.. i think it should forward the request  
> to mongrel, localhost:3000.. but how will the mongrel figure out where are  
> the ruby apps? it will get a request for example.tld or example6.tld and  
> example4.tld at the same time.. .. ??

You need to have at least one mongrel instance per domain, and set  
up your httpd proxy accordingly.

---

<div class="post-metadata">

**Author:** ![Nagy\_TamSSSSs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/5f9b8f/32.png) [@Nagy\_TamSSSSs](https://www.ruby-forum.com/u/Nagy_TamSSSSs)\
**Post date:** [March 24, 2010, 11:05pm UTC](https://www.ruby-forum.com/t/virtualhost-like-in-the-apache-php-world/185704/4 "2010-03-24T23:05:33Z")

</div>

Thank you, Jonathan! but i'd like to try out Mongrel..so, I set the  
apache with mod\_proxy.. i think it should forward the request to  
mongrel, localhost:3000.. but how will the mongrel figure out where are  
the ruby apps? it will get a request for example.tld or example6.tld and  
example4.tld at the same time.. .. ??

Jonathan R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) Ã­rta:

> 

[\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
ÃšjdonsÃ¡g!  
MegÃ©rkezett a RIGHT GUARD fÃ©rfi testÃ¡polÃ¡si termÃ©kcsalÃ¡d! Most 25%  
kedvezmÃ©nnyel!  
AkÃ¡r 48 Ã³rÃ¡s hatÃ¡sos vÃ©delem a testszag ellen!  
](http://ad.adverticum.net/b/cl,1,73468,1598288,1592431/click.prm)

---

<div class="post-metadata">

**Author:** ![Nagy\_TamSSSSs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/5f9b8f/32.png) [@Nagy\_TamSSSSs](https://www.ruby-forum.com/u/Nagy_TamSSSSs)\
**Post date:** [March 25, 2010, 3:44pm UTC](https://www.ruby-forum.com/t/virtualhost-like-in-the-apache-php-world/185704/5 "2010-03-25T15:44:42Z")

</div>

Thank you Hassan, James!

So i will need one mongrel per domain. I think I can't carry out  
this because I have a thousands of domains.

I think i will try the rack-thing James mentioned. I assume i can't  
run individual ruby script files but whole apps, one app for one domain.

ooohh so hard… 🙂

[\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
ÃšjdonsÃ¡g!  
MegÃ©rkezett a RIGHT GUARD fÃ©rfi testÃ¡polÃ¡si termÃ©kcsalÃ¡d! Most 25%  
kedvezmÃ©nnyel!  
AkÃ¡r 48 Ã³rÃ¡s hatÃ¡sos vÃ©delem a testszag ellen!  
](http://ad.adverticum.net/b/cl,1,73468,1598288,1592431/click.prm)

---

<div class="post-metadata">

**Author:** ![Nagy\_TamSSSSs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/5f9b8f/32.png) [@Nagy\_TamSSSSs](https://www.ruby-forum.com/u/Nagy_TamSSSSs)\
**Post date:** [March 25, 2010, 4:32pm UTC](https://www.ruby-forum.com/t/virtualhost-like-in-the-apache-php-world/185704/6 "2010-03-25T16:32:43Z")

</div>

On 25 Mar 2010, at 14:34, Nagy TamÃ¡s wrote:

> Thank you Hassan, James!
> 
> So i will need one mongrel per domain. I think I can’t carry out this because I have a thousands of domains.

That sounds like a recipe for out of memory errors and cross-application  
errors taking down the whole set at the same time. It also sounds like  
it’s better suited to passenger.

> I think i will try the rack-thing James mentioned. I assume i can’t run individual ruby script files but whole apps, one app for one domain.

You can load whatever you like, and run anything that responds to #call,  
in the standard rack manner. What you won’t be able to do, is load  
different versions of dependencies into the same process and expect to  
be bug free.

---

<div class="post-metadata">

**Author:** ![Nagy\_TamSSSSs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/5f9b8f/32.png) [@Nagy\_TamSSSSs](https://www.ruby-forum.com/u/Nagy_TamSSSSs)\
**Post date:** [March 25, 2010, 5:04pm UTC](https://www.ruby-forum.com/t/virtualhost-like-in-the-apache-php-world/185704/7 "2010-03-25T17:04:21Z")

</div>

Do you want a seperate app per domain, or do you want one app handling  
multiple domains?

If you want a seperate app per domain, I think you’d need a mongrel per  
domain too, I don’t see any other way to do it.

If you want one app that handles multiple domains, than it’s up to you  
to write an app that can do that, and it’s not a mongrel issue.

Jonathan

---

<div class="post-metadata">

**Author:** ![Nagy\_TamSSSSs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/5f9b8f/32.png) [@Nagy\_TamSSSSs](https://www.ruby-forum.com/u/Nagy_TamSSSSs)\
**Post date:** [March 25, 2010, 10:17pm UTC](https://www.ruby-forum.com/t/virtualhost-like-in-the-apache-php-world/185704/8 "2010-03-25T22:17:00Z")

</div>

On 25 Mar 2010, at 14:52, Jonathan R. wrote:

> Do you want a seperate app per domain, or do you want one app handling multiple domains?
> 
> If you want a seperate app per domain, I think you’d need a mongrel per domain too, I don’t see any other way to do it.

map “[http://domain1.com/](http://domain1.com/)” do  
run App1.new  
end

map “[http://domain2.com/](http://domain2.com/)” do  
run App2.new  
end

I see a way to do it.

---

<div class="post-metadata">

**Author:** ![Nagy\_TamSSSSs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/5f9b8f/32.png) [@Nagy\_TamSSSSs](https://www.ruby-forum.com/u/Nagy_TamSSSSs)\
**Post date:** [March 25, 2010, 11:09pm UTC](https://www.ruby-forum.com/t/virtualhost-like-in-the-apache-php-world/185704/9 "2010-03-25T23:09:41Z")

</div>

On Thu, Mar 25, 2010 at 2:04 PM, James T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> map “[http://domain1.com/](http://domain1.com/)” do  
> run App1.new  
> end
> 
> map “[http://domain2.com/](http://domain2.com/)” do  
> run App2.new  
> end
> 
> I see a way to do it.

OK, I’ve never used Rack as a standalone entity; how exactly does  
this work in a Rails context?

Say, I have a directory structure like

/webapps/app1  
/webapps/app2

where both app1 and app2 are Rails apps.

Where does the above code go, and what exactly would I be invoking?

---

<div class="post-metadata">

**Author:** ![Nagy\_TamSSSSs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/5f9b8f/32.png) [@Nagy\_TamSSSSs](https://www.ruby-forum.com/u/Nagy_TamSSSSs)\
**Post date:** [March 26, 2010, 10:13am UTC](https://www.ruby-forum.com/t/virtualhost-like-in-the-apache-php-world/185704/10 "2010-03-26T10:13:56Z")

</div>

Ok, then it will be Rack. anyway, i want to use the whole ruby as php:  
example.tld/rubyscript1.rbexample.tld/rubyscript2.rbexample2.tld/rubyappexample2.tld/rubyapp/rubyscript.rb  
where also works any Rails app…

[\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
ÃšjdonsÃ¡g!  
MegÃ©rkezett a RIGHT GUARD fÃ©rfi testÃ¡polÃ¡si termÃ©kcsalÃ¡d! Most 25%  
kedvezmÃ©nnyel!  
AkÃ¡r 48 Ã³rÃ¡s hatÃ¡sos vÃ©delem a testszag ellen!  
](http://ad.adverticum.net/b/cl,1,73468,1598288,1592431/click.prm)

---

<div class="post-metadata">

**Author:** ![Nagy\_TamSSSSs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/5f9b8f/32.png) [@Nagy\_TamSSSSs](https://www.ruby-forum.com/u/Nagy_TamSSSSs)\
**Post date:** [March 25, 2010, 9:48am UTC](https://www.ruby-forum.com/t/virtualhost-like-in-the-apache-php-world/185704/11 "2010-03-25T09:48:11Z")

</div>

On 24 Mar 2010, at 22:13, Hassan S. wrote:

> 2010/3/24 Nagy TamÃ¡s [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > but i’d like to try out Mongrel..  
> > so, I set the apache with mod\_proxy.. i think it should forward the request  
> > to mongrel, localhost:3000.. but how will the mongrel figure out where are  
> > the ruby apps? it will get a request for example.tld or example6.tld and  
> > example4.tld at the same time.. .. ??
> 
> You need to have at least one mongrel instance per domain, and set  
> up your httpd proxy accordingly.

Actually, you can use rack to do it:

map “[http://domain1/](http://domain1/)” do  
run App1  
end

map “[http://domain2/](http://domain2/)” do  
run App2  
end

Then specify multiple vhost aliases in the apache proxy configuration
