Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am building a webapp with Django and among other features I would like people to use their own domain so I thought about telling them to redirect their desired CNAME record to my server. How can I get my server to update the apache available and enlisted sites automatically? Or is there an easier solution?

P.S: How does Tumblr or MobileMe do it?

Thanks, Max

share|improve this question
up vote 2 down vote accepted

You are not going to be able to detect when someone points a DNS entry to your server (be it an A record, a CNAME, or anything else) unless the DNS zone is also being managed by your service.

I would suggest having Apache set to have one vhost that responds to all domain names (that are not explicitly listed for other vhosts) and create a mod_rewrite mapping rule to map the domains to specific directories on the server, i.e. http://some.domain.tld/ to be service from /var/www/some.domain.tld/ or /home/some.domain.tld.

That way no Apache configuration changes need to be made for each new domain, you just need to make sure the directory exists. You can automate this by having an intelligent 404 handler that creates the directory the first time it is requested and redirects the browser back - take care though not to make this in such a way as it still reacts to other 404 errors correctly and make sure it properly sanitises its inputs so it can't be used for a DoS attack or to create structures that would make other attacks easier.

share|improve this answer

Your application can detect which domain it is being asked to serve for based on the Host header sent to the application (if necessary, tell the front-end webserver to pass the header through), and from there you can do whatever domain-specific actions are required.

share|improve this answer

Your Answer


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.