Multiple customer instances of an application, under a single application.

What I need is to allow multiple users, to connect to my Apache Web server, by passing different url like : etc.

What I want my Apache server to do, is pass all request that are not directed to a certain list of existing hosts (like and over to my Rails application, by setting a RequestHeader to identify the requested host, something like :

RequestHeader "INSTANCE_NAME" = customer1 #for

Thanks for your help!

Ps.: The end goal is to offer software slices as a service, but having all those customers managed under 1 application running. Not 1 app per customer.

Accepted Answer

Using a standard VirtualHost configuration you can do this:

NameVirtualHost *:80

<VirtualHost *:80>
  ServerAlias *

  DocumentRoot /web/

This will capture all requests that are not already captured by other VirtualHost entries.

When your application receives the request, you will have the request variable set with the host-name provided. This is available to any ActionController:

From there you can load the appropriate data in some kind of before_filter, as is typically done like:

before_filter :load_client

def load_client
  @client = Client.find_by_hostname!(
rescue ActiveRecord::RecordNotFound
  render(:partial => 'client_not_found', :status => :not_found)

So long as the client has the hostname populated correctly, this will find them on each page load.

Written by tadman
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the community.
It is licensed under cc-wiki