Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|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 '12 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 '12 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 '12 at 8:57
add comment

1 Answer

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.

share|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 '12 at 13:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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