# One Rails App - thousands of vHosts pointing to it

**URL:** <https://www.ruby-forum.com/t/one-rails-app-thousands-of-vhosts-pointing-to-it/144272>\
**Category:** Deployment\
**Created:** [July 28, 2008, 12:20am UTC](https://www.ruby-forum.com/t/one-rails-app-thousands-of-vhosts-pointing-to-it/144272 "2008-07-28T00:20:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffpritchard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@jeffpritchard](https://www.ruby-forum.com/u/jeffpritchard)\
**Post date:** [July 28, 2008, 12:20am UTC](https://www.ruby-forum.com/t/one-rails-app-thousands-of-vhosts-pointing-to-it/144272/1 "2008-07-28T00:20:57Z")

</div>

I have a new client with a project that will be organized a lot like  
“[blogspot.com](http://blogspot.com)” (aka blogger) where there are a large number of content  
providers, and each one of those people gets their own subdomain off the  
main “[blogger.com](http://blogger.com)” domain.

The obvious (though perhaps not the best) way to do this is to have the  
Rails app create a new virtual host block in the apache config for each  
one of these content providers and their subdomain.

My concern is that the vHosts in Apache were probably designed as a way  
to have two or three, maybe a half dozen or more separate things running  
on the server…but a few thousand!!!

Does anyone have any experience putting thousands of vHosts into an  
apache config? Does this scale that high without creating some sort of  
stability or speed problems? Do you need gobs 'o RAM for the apache  
server to keep track of all those vHosts? Does it take hours for the  
Apache server to start up?

Does anyone have a suggestion for a much better way to do this? Am I  
re-inventing an existing wheel?

many thanks for your wisdom.

thanks,  
jp

---

<div class="post-metadata">

**Author:** ![jeffpritchard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@jeffpritchard](https://www.ruby-forum.com/u/jeffpritchard)\
**Post date:** [July 28, 2008, 1:06am UTC](https://www.ruby-forum.com/t/one-rails-app-thousands-of-vhosts-pointing-to-it/144272/2 "2008-07-28T01:06:40Z")

</div>

You can use a wildcard in apache’s configuration  
ServerName [blogger.com](http://blogger.com)  
ServerAlias \*.blogger.com

Then in rails you can access the subdomain(s) via request.subdomains

A similar approach is spelled out at:  
[http://wiki.rubyonrails.org/rails/pages/HowToUseSubdomainsAsAccountKeys](http://wiki.rubyonrails.org/rails/pages/HowToUseSubdomainsAsAccountKeys)

On Sun, Jul 27, 2008 at 3:20 PM, Jeff P.

---

<div class="post-metadata">

**Author:** ![jeffpritchard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@jeffpritchard](https://www.ruby-forum.com/u/jeffpritchard)\
**Post date:** [July 28, 2008, 2:42am UTC](https://www.ruby-forum.com/t/one-rails-app-thousands-of-vhosts-pointing-to-it/144272/3 "2008-07-28T02:42:54Z")

</div>

Shawn Balestracci wrote:

> You can use a wildcard in apache’s configuration  
> ServerName [blogger.com](http://blogger.com)  
> ServerAlias \*.blogger.com
> 
> Then in rails you can access the subdomain(s) via request.subdomains
> 
> A similar approach is spelled out at:  
> [http://wiki.rubyonrails.org/rails/pages/HowToUseSubdomainsAsAccountKeys](http://wiki.rubyonrails.org/rails/pages/HowToUseSubdomainsAsAccountKeys)
> 
> On Sun, Jul 27, 2008 at 3:20 PM, Jeff P.

Very cool! Thanks Shawn!

I wonder, can you do _._ and also get the domain?

(naturally, he wants to allow some customers to register a domain name  
and use that as well)

thanks again!

jp

---

<div class="post-metadata">

**Author:** ![jeffpritchard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@jeffpritchard](https://www.ruby-forum.com/u/jeffpritchard)\
**Post date:** [July 28, 2008, 2:53am UTC](https://www.ruby-forum.com/t/one-rails-app-thousands-of-vhosts-pointing-to-it/144272/4 "2008-07-28T02:53:37Z")

</div>

On Mon, 2008-07-28 at 00:20 +0200, Jeff P. wrote:

> My concern is that the vHosts in Apache were probably designed as a way  
> to have two or three, maybe a half dozen or more separate things running  
> on the server…but a few thousand!!!
> 
> Does anyone have any experience putting thousands of vHosts into an  
> apache config? Does this scale that high without creating some sort of  
> stability or speed problems? Do you need gobs 'o RAM for the apache  
> server to keep track of all those vHosts? Does it take hours for the  
> Apache server to start up?

On RubyForge we have over 6000 virtual hosts configured inside one  
Apache server and haven’t seen any problems. Restarts take 10-15  
seconds. The machine has 8 GB of RAM, but Apache doesn’t use much of it  
since the virtual hosts are mostly static content.

Yours,

Tom

---

<div class="post-metadata">

**Author:** ![jeffpritchard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@jeffpritchard](https://www.ruby-forum.com/u/jeffpritchard)\
**Post date:** [July 28, 2008, 3:01am UTC](https://www.ruby-forum.com/t/one-rails-app-thousands-of-vhosts-pointing-to-it/144272/5 "2008-07-28T03:01:07Z")

</div>

Tom C. wrote:

> On Sun, 2008-07-27 at 20:52 -0400, Tom C. wrote:
> 
> > On RubyForge we have over 6000 virtual hosts configured inside one  
> > Apache server and haven’t seen any problems. Restarts take 10-15  
> > seconds. The machine has 8 GB of RAM, but Apache doesn’t use much of it  
> > since the virtual hosts are mostly static content.
> 
> That said, I think Shawn’s suggestion is probably the way to go,
> 
> Yours,
> 
> Tom

Thanks Tom. Interesting that it can handle that many with ease.

May use Shawn’s method for the subdomains and vHosts for all of the  
user-registered domains.

jp

---

<div class="post-metadata">

**Author:** ![jeffpritchard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@jeffpritchard](https://www.ruby-forum.com/u/jeffpritchard)\
**Post date:** [July 28, 2008, 2:53am UTC](https://www.ruby-forum.com/t/one-rails-app-thousands-of-vhosts-pointing-to-it/144272/6 "2008-07-28T02:53:37Z")

</div>

On Sun, 2008-07-27 at 20:52 -0400, Tom C. wrote:

> On RubyForge we have over 6000 virtual hosts configured inside one  
> Apache server and haven’t seen any problems. Restarts take 10-15  
> seconds. The machine has 8 GB of RAM, but Apache doesn’t use much of it  
> since the virtual hosts are mostly static content.

That said, I think Shawn’s suggestion is probably the way to go,

Yours,

Tom
