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.

I am going to build an album website using Django 1.5. one of the feature I want to provide my members is to use their own domain name.

www.albumn123.com/user/mike

www.mike.com

now, the site is almost ready. but this domain part I am still clueless. I dont think I can do it just in the coding. I believe I have to config something in the server. this is why I post my question here.

Please point me to a right direction, let me know how I should get started. if possible i want to automate this whole process.

my dev stack:

Unbuntu 12.04

Django 1.5

Gunicorn is the server.

share|improve this question
add comment

closed as off topic by Bryan, Ward, mdpc, Jenny D, Cakemox Jun 7 '13 at 12:46

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

I'm not familiar with Gunicorn specifically, but if it's anything like the way Apache (and several other servers) works, it should accept requests for all domains that point to it. It's then up to you to detect in code what the requested domain was and handle it accordingly.

For example, in PHP you can use $_SERVER['HTTP_HOST'] to find the domain name requested, and then build your page depending on the domain. You'll have to have a mapping somewhere to link the arbitrary domain names to your users.

share|improve this answer
add comment

Wildcard VirtualHost + CNAME

There are two parts to this approach. I will comment on the server side as I am not a programmer.

Apache WildCard VirtualHost

You can configure a wildcard virtual host in Apache by setting the servername or alias to "*".

<VirtualHost 0.0.0.0:80>
ServerName domain.com
ServerAlias *
...
</VirtualHost>

This will make this virtual host the default for any on the selected IP address. If you host multiple sites on your server, I recommend you put this virtualhost on its own IP.

CNAME

For the custom domain name, you can have your client enter a CNAME to map their custom domain to your domain.

www.user.com CNAME www.albumn123.com

Application Logic

Your application will then need to take an environment variable or host header and then deliver the correct web site. Also be sure to handle non-existing domains and normalize your URLS (www.domain.com vs. domain.com) to make things easier to manage.

Yes you can do this with RewriteRules, but in my experience it does not scale well and be be cumbersome if you have to re-organize your filesystem.

share|improve this answer
add comment

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