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.

link|improve this question
Would pointing the DNS of customer50.mycompany.com to the server that does have their data work for you? – becomingwisest Jan 2 at 7:21
If you don't need a centralized control/access to your web app, you can simply insert a new DNS record for each new customer that points to the right server. That's it! – Khaled Jan 2 at 8:20
Christopher, @Khaled: That's true, and a possible alternative to our current idea of using GeoIP DNS. However, even in that case, 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. (updating question with this info) – Matt White Jan 2 at 8:57
feedback

2 Answers

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.

link|improve this answer
Thanks. The trouble with an HTTP redirect is that the redirect needs to be transparent. That is, a request for http://customer1.mycompany.com/rails_app/item1 shouldn't simply redirect to http://1.2.3.4/rails_app/item1 or http://customer1.mycompanyineurope.com/rails_app/item1. The URL needs to be the same no matter what server I hit. That's why I was thinking a reverse proxy in Apache would be the only way to do this. – Matt White Jan 2 at 13:21
feedback

hi there im working on something like this and i cant get it work properly.

  1. main server is located in london, using geoip to get continet code to show of a visitor connecting to web server. there are several web domains connecting to it as http and www as well

  2. i want to incoming header and address using continent geoip code forward it to another reverse proxy located in another continent using geoip. reverse proxy has already a database of running web addresses and where to looking for files on original web server

  3. i just do not know how to use header coming to main server and forward it to reverse proxy so reverse proxy would see it as coming straight to it. main server should not have a database of running web sites. just a plain redirection using geoip to reverse proxy on another continet

i know this shouldbe easy i just need help

thanx, john

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.