In Apache 2.2, is there a way to forward certain subdomains to another server (in another datacenter) based on a lookup table of subdomain/IP address mappings (provided in a file or database)?
The reason I need this is that I have a SaaS web app where each customer gets their own subdomain, i.e. customer1.mycompany.com
, customer2.mycompany.com
, etc. If Apache receives a request for a customer whose data is not stored on the current server, I want Apache to simply forward (proxy?) the request on to the correct server. The number of customers will be continually increasing (hopefully!) and I cannot reload Apache each time that happens.
UPDATE:
Our current idea is to use GeoIP DNS to send customers to the correct (nearest) server, and if a customer is accidentally sent to the wrong server (e.g. they are traveling), then we would need to do the proxying. However, even if we added a DNS entry for each subdomain, there could still be requests that end up at the wrong server when an account is first created, or when it is moved from one server to another. For various reasons, we don't want to set a really low TTL on the DNS entries.
One way to implement your idea to create your own index file (using PHP/perl or whatever language you prefer). The index page will simply query the DB/file mapping of domains and send redirect to the appropriate server. In this case, you don't need to worry about DNS caching.