views:

845

answers:

5

What should do to setup a sub-domain for the users when they sign-up into my site.

What are the infrastructure required? I am using Linux servers.

+3  A: 

You can make a CNAME entry/ A Record in your DNS settings, for each subdomain

A CNAME record is a record in your Domain Management Settings that allows you to control a subdomain of your domain.

To automate it along with registration, you can write a script which is executed for each user, when s/he registers.

You can refer to this link, as well, for a step-by-step process for Apache:

How to setup subdomains in apache

(since you mentioned Linux, I assume it must be APache. Please mention if it is otherwise)

Alternate Solution

You can also refer to the wildcard solution, given by Alnitak, in the same thread. I find his is an easier way. :)

Mohit Nanda
It doesn't have to be a CNAME. I do subdomains with A records. Granted, I've got more work to do if my IP ever changes, but that's not going to happen.
Paul Tomblin
I know thats a pretty safe assumption to make. And I admit CNAME is not the only way. I'll modify my answer.
Mohit Nanda
+4  A: 

You can either use a specific DNS (CNAME or A/AAAA) entry for each known subdomain, or a wild-card DNS entry that'll accept *.example.com:

$ORIGIN example.com
foo     IN A 12.34.6.78
bar     IN A 12.34.6.78

or

$ORIGIN example.com
*       IN A 12.34.6.78

The advantage of this latter is that no changes are required to either DNS or Apache configuration once the service is running. The disadvantage is that all such wildcard lookups must (by definition) end up returning the same IP address.

The Apache configuration will depend on your requirements, both for end-user control and security. Note that if the users have permission to run CGI scripts on the server then additional setup will be needed to ensure that that's done securely.

Depending on whether content is static or dynamic this will also affect your configuration:

  1. Use mod_vhost_alias to map individual virtual hosts into their individual directories on the server.

  2. If you really want, create a separate <VirtualHost> section for each known site, but then you'll have to restart Apache each time a new user signs up

  3. Use a single <VirtualHost> and then look at the hostname part of the requested URL (from the $SERVER_NAME environment variable) in the scripts that render the output to figure out which user's content to display.

Alnitak
I tried it. It is definitely better than my solution above. +1
Mohit Nanda
which of the three options I suggested did you use?
Alnitak
A: 

infrastructure includes access the the dns server to add a wildcard entry, and rewrite rules in Apache.

Try these answers:

or this link:

Colin Pickard
A: 

If your using Linux server's I'm assuming your using Apache as your webserver.

You'll have to setup proper DNS routing for the sub domain as well as a virtual host.

Virtual Hosts are fairly easy to setup but I'm not sure how easy it is to do them on the fly progmatically.

Most of the time it's as easy as editing your apache config file and adding the following:

Port 80
ServerName www.mydomain.com

NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/user-bob
ServerName bob.mydomain.com
...
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/user-sally
ServerName sally.mydomain.com
...
</VirtualHost>

The VirtualHost Documention will probably of some use to you.

Brian Gianforcaro
A: 

Apache allows you to specify any number of 'sites' based on subdomains on a single server. Creating a new 'site definition' file with the appropriate subdomain information in it, along with proper DNS wildcards, will do what you want.

In other words, the process is like this:

  1. Setup wildcards so that *.mysite.com directs to the proper server.
  2. When a new user signs up, create the proper Apache site definition file - you'll probably have a base template that you put the right subdomain information into and save.
  3. Make Apache re-read its configuration.
  4. Profit.

IMPORTANT This is based on a Debian-style Apache configuration, where the config files are included in a directory, and the main configuration reads all the config files in that directory. This will simplify things a great deal, because adding/removing subdomains will mean adding/removing files, rather than editing a single file, and so the process will be much easier to automate.

Harper Shelby