The first step is to configure settings with your dynamic DNS service. The following instructions are for No-IP, but they should be very similar to other services such as DynDNS:
- Navigate to the settings page for your domain.
- Find the "Enable wildcards" option and enable it. This directs all domain requests, no matter the subdomain, to Apache. Here is a picture for No-IP:
After configuring your provider, next we need to configure Apache. In order to direct to the right location on the server, you need to configure Apache to know where each subdomain should be directed.
- On your server, navigate to
/etc/apache2/sites-available. This path is for Ubuntu, you will probably need to work with httpd.conf on other systems. This is where Apache gets information about sites and subdomains on Ubuntu.
- If you have not already done so already, create a new .conf file. Although you can name it whatevery you want, it is useful to name it with the format, [yourdomain.com].conf. This file will be used instead of
defaultbecause it is easer (for me at least) to start from scratch for something like this.
- Open up the file, and add the following lines:
<VirtualHost *> DocumentRoot /var/web/www </VirtualHost>This is the main entry, it directs all of the undefined subdomains (which we will define later - be patient) to /var/web/www. Of course, you will need to add your own configuration like log files; this is just the bare minimum to get you going. The path can be whatever you like. Note that your changes will not be added until step #6, so hang out.
- Now you can define other subdomains and their paths. Here is an example for foo.clustur.com:
<VirtualHost *> ServerName foo.clustur.com DocumentRoot /var/web/foo </VirtualHost>Notice the only difference is the ServerName attribute. You can add as many of these directives as you would like into your .conf file.
- Now we need to enable the settings we just made:
sudo a2dissite default sudo a2ensite [yourdomain.com].confThe first line disables the old default configuration file, and the second line enables your new .conf file, whatever you named it.
- Finally, we can restart apache:
sudo /etc/init.d/apache2 gracefulNow all of your subdomains should work! If you're stumped or have any suggestions, please feel free to comment - I'll do my best to help you out.