# Creating virtual hosts with Mongrel?

**URL:** <https://www.ruby-forum.com/t/creating-virtual-hosts-with-mongrel/160797>\
**Category:** Rails\
**Created:** [February 19, 2009, 8:03pm UTC](https://www.ruby-forum.com/t/creating-virtual-hosts-with-mongrel/160797 "2009-02-19T20:03:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![groovetrain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b4bc9f/32.png) [@groovetrain](https://www.ruby-forum.com/u/groovetrain)\
**Post date:** [February 19, 2009, 8:03pm UTC](https://www.ruby-forum.com/t/creating-virtual-hosts-with-mongrel/160797/1 "2009-02-19T20:03:06Z")

</div>

Does anyone know how to use Mongrel to create virtual hosts? My  
production site will have all kinds of domains pointing to it, and I  
also need to figure out how to do subdomains. Rails should react to  
the host name, doing a lookup based on the name and pull different  
records from the database based on this.

For example, I’d like [www.mysite.com](http://www.mysite.com) to point back to 127.0.0.1:3000,  
and the same for [username.productionsite.com](http://username.productionsite.com).

I’m using OS X Leopard

Any references or council will be appreciated, thanks in advance!

groove

---

<div class="post-metadata">

**Author:** ![groovetrain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b4bc9f/32.png) [@groovetrain](https://www.ruby-forum.com/u/groovetrain)\
**Post date:** [February 19, 2009, 8:11pm UTC](https://www.ruby-forum.com/t/creating-virtual-hosts-with-mongrel/160797/2 "2009-02-19T20:11:21Z")

</div>

You might consider switching to Passenger for stuff like this. This is  
how our team is tackling this without much effort. Takes just a few  
minutes to setup/switch. Here is a writeup on it (for OS X).

[http://www.robbyonrails.com/articles/2009/02/11/switch-to-passenger-mod\_rails-in-development-on-osx-in-less-than-7-minutes-or-your-money-back](http://www.robbyonrails.com/articles/2009/02/11/switch-to-passenger-mod_rails-in-development-on-osx-in-less-than-7-minutes-or-your-money-back)

Cheers,  
Robby

On Thu, Feb 19, 2009 at 11:02 AM, groovetrain [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’m using OS X Leopard
> 
> Any references or council will be appreciated, thanks in advance!
> 
> groove
> 
> >

–  
Robby R.  
Chief Evangelist, Partner

PLANET ARGON, LLC  
design // development // hosting w/Ruby on Rails

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[http://robbyonrails.com/](http://robbyonrails.com/)  
[http://twitter.com/planetargon](http://twitter.com/planetargon)  
aim: planetargon

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4068 [fax]

---

<div class="post-metadata">

**Author:** ![groovetrain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b4bc9f/32.png) [@groovetrain](https://www.ruby-forum.com/u/groovetrain)\
**Post date:** [February 19, 2009, 8:16pm UTC](https://www.ruby-forum.com/t/creating-virtual-hosts-with-mongrel/160797/3 "2009-02-19T20:16:04Z")

</div>

On 19 Feb 2009, at 19:02, groovetrain wrote:

> Does anyone know how to use Mongrel to create virtual hosts? My  
> production site will have all kinds of domains pointing to it, and I  
> also need to figure out how to do subdomains. Rails should react to  
> the host name, doing a lookup based on the name and pull different  
> records from the database based on this.

Typically people use nginx, apache etc… to handle the nuts and bolts  
side of virtual hosts. There’s railscasts on using subdomains  
([#123 Subdomains - RailsCasts](http://railscasts.com/episodes/123-subdomains)  
)

Fred

---

<div class="post-metadata">

**Author:** ![groovetrain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b4bc9f/32.png) [@groovetrain](https://www.ruby-forum.com/u/groovetrain)\
**Post date:** [February 20, 2009, 1:58am UTC](https://www.ruby-forum.com/t/creating-virtual-hosts-with-mongrel/160797/4 "2009-02-20T01:58:56Z")

</div>

Mongrel will respond to everything with the same app. The app, however  
has access to A request.env variable which has hostname in it. Inspect  
it to find out more.

Blog: [http://random8.zenunit.com/](http://random8.zenunit.com/)  
Learn rails: [http://sensei.zenunit.com/](http://sensei.zenunit.com/)

---

<div class="post-metadata">

**Author:** ![groovetrain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b4bc9f/32.png) [@groovetrain](https://www.ruby-forum.com/u/groovetrain)\
**Post date:** [February 19, 2009, 9:00pm UTC](https://www.ruby-forum.com/t/creating-virtual-hosts-with-mongrel/160797/5 "2009-02-19T21:00:49Z")

</div>

Both of these are very helpful, thank you both so much.

Does passenger allow for full domain names? Kindof like pseudo-hosts,  
like having a full [www.alskdfjhdsaf.com](http://www.alskdfjhdsaf.com) pointed back to localhost:  
3000?

Is there some way of doing this by hacking the /etc/hosts file?

Groove

On Feb 19, 2:15 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![groovetrain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b4bc9f/32.png) [@groovetrain](https://www.ruby-forum.com/u/groovetrain)\
**Post date:** [February 21, 2009, 7:07pm UTC](https://www.ruby-forum.com/t/creating-virtual-hosts-with-mongrel/160797/6 "2009-02-21T19:07:36Z")

</div>

Groove,

Did you read my article? We do the following for subdomains as well.

- 

[http://www.robbyonrails.com/articles/2009/01/11/subdomain-accounts-with-ruby-on-rails-explained](http://www.robbyonrails.com/articles/2009/01/11/subdomain-accounts-with-ruby-on-rails-explained)

Cheers,  
Robby

On Thu, Feb 19, 2009 at 11:59 AM, groovetrain [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > > records from the database based on this.  
> > > and the same for [username.productionsite.com](http://username.productionsite.com).
> > 
> > > I’m using OS X Leopard
> > 
> > > Any references or council will be appreciated, thanks in advance!
> > 
> > > groove

–  
Robby R.  
Chief Evangelist, Partner

PLANET ARGON, LLC  
design // development // hosting w/Ruby on Rails

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[http://robbyonrails.com/](http://robbyonrails.com/)  
[http://twitter.com/planetargon](http://twitter.com/planetargon)  
aim: planetargon

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4068 [fax]
