Tuesday, August 18, 2009

Setting up Hardy Heron with Apache2 and multiple Domains

Finally cracked setting up multiple domains on my shiny new Ubuntu server. In case it helps anyone else out of a hold, here are my tips for easy domain management.

1. Use GoDaddy and their total DNS option (google for instructions) This means you don't have to worry about a name server. Just setup your domains and subdomains with an A record that points to your IP address. If your domain is currently pointing to a nameserver other than GoDaddy's change the nameserver option to Forwarding - wait a few mins, then you use Total DNS.


2. in /etc/apache2/site-available, create one file for each domain, I just used the domain name for the filename, eg. mydomain.com This should contain something like:



ServerName mydomain.com
ServerAlias www. mydomain.com
DocumentRoot /home/django/mydomain

...and all the other usual stuff ...




3. in /etc/apache2/sites-enabled create a dynamic link to the file you just created in sites-available. Ordering is import so add a sequence number to the beginning of the name. Ensure sub-domains come before main domain entry.

eg.

ln -s /etc/apache2/sites-available/blog.mydomain.com 010-blog.mydomain.com
ln -s /etc/apache2/sites-available/mydomain.com 011-mydomain.com


4. And this is what I had missed. Ensure there is a default file in your sites-available that includes this line:

NameVirtualHost *:80


That's all I have in mine. And have a dynamic link in sites-enabled so that DEFAULT IS RUN FIRST.

eg, ln -s /etc/apache2/sites-available/default 000-default

5. restart apache eg. /etc/init.d/apache2 restart

6. Cross fingers and enter domain in the browser.

If you are doing this all at once, it takes a while for the changes to propogate through from godaddy, so be patient.

No comments: