2 min read

Tags

  • Bytes
  • ubuntu
  • dyndns
  • server
  • no-ip
  • apache
  • subdomain
When I was setting up my server, I was faced with the problem of configuring subdomains to work with a dynamic DNS service such as DynDNS or No-IP. I recently had a user on the Ubuntu Forums ask me how I ended up getting things to work, so I wrote this article to explain.

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:
  1. Navigate to the settings page for your domain.
     
  2. 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.
  1. 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.
     
  2. 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 default because it is easer (for me at least) to start from scratch for something like this.
     
  3. 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.
     
  4. 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.
     
  5. Now we need to enable the settings we just made:
    sudo a2dissite default
    sudo a2ensite [yourdomain.com].conf
    The first line disables the old default configuration file, and the second line enables your new .conf file, whatever you named it.
     
  6. Finally, we can restart apache:
    sudo /etc/init.d/apache2 graceful
    Now 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.