Ruby Forum Rails deployment > One Rails App - thousands of vHosts pointing to it

Posted by Jeff Pritchard (jeffpritchard)
on 28.07.2008 00:20
I have a new client with a project that will be organized a lot like
"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" 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
Posted by Shawn Balestracci (Guest)
on 28.07.2008 01:06
(Received via mailing list)
You can use a wildcard in apache's configuration
ServerName 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

On Sun, Jul 27, 2008 at 3:20 PM, Jeff Pritchard
Posted by Jeff Pritchard (jeffpritchard)
on 28.07.2008 02:42
Shawn Balestracci wrote:
> You can use a wildcard in apache's configuration
> ServerName 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
> 
> On Sun, Jul 27, 2008 at 3:20 PM, Jeff Pritchard

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
Posted by Tom Copeland (Guest)
on 28.07.2008 02:53
(Received via mailing list)
On Mon, 2008-07-28 at 00:20 +0200, Jeff Pritchard 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
Posted by Tom Copeland (Guest)
on 28.07.2008 02:53
(Received via mailing list)
On Sun, 2008-07-27 at 20:52 -0400, Tom Copeland 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
Posted by Jeff Pritchard (jeffpritchard)
on 28.07.2008 03:01
Tom Copeland wrote:
> On Sun, 2008-07-27 at 20:52 -0400, Tom Copeland 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