Questions regarding DNS configuration for multiple subdomain under 1 IP address?

  • Posted February 23, 2014

Thank you for help in advance.

I recently registered a domain name and wish to create multiple subdomains, which are to be hosted on a droplet under a single IP address using virtual hosts. The following are my desired configuration.

Domain name:, subdomain 1: test, subdomain 2: forum. Droplet IP: Alias “” point to subdomain 1 and “” point to subdomain 2.

Current DNS Configuration: (each field sepated by “|”) A Record: @ | A Record: forum | A Record: test |

CNAME: * | @ CNAME: *.forum | CNAME: *test |


I created additional CNAME record as follow to point anything other than the alias specified to

CNAME: * |

The CNAME entry worked and it pointed and to, however, I got error messages on the control panel page after adding the above entry.

My other questions are regarding to virtual host configuration:

Do I need to create a separate virtual host configuration file for each virtual host under /etc/apache2/sites-available or I simply add a <VirtualHost> block on the existing default configuration?

Do each virtual host need to listen to a different port for them to work?

My config are as follow: /etc/apache2/sites-available/default ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    <Directory /var/www/>

/etc/apache2/sites-available/ #NameVirtualHost *:80 #uncomment lead to apache2 startup error <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName ServerAlias

DocumentRoot /var/www/

    <Directory />
            Options FollowSymLinks
            AllowOverride None
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all

I followed tutorial on these setup, but I am unsure if I need to have 1 config file for each virtual host or 1 config file for multiple virtual host.

I apologise if the question seem obscure, please let me know so I can explain better. Thank you for your help!


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

First off there are quite a few ways you could set this up but I will explain how I would do it. From what I have gathered you basically want to have 3 separate sites,, and and I will assume that that each will reside in seperate folders in the /var/www/ dir. The best way (in my opinion of course) would be to create 3 separate a records, “@” for, “test” for, and “forum” for and point them all to the IP address of your server/droplet. The create one cname “www” that points to Then create 3 separate vhost files in /etc/apache2/sites-available/ (a simple way to do this is to run the command “mv default” file extinsions are not important to LINUX so I prefer to name the vhost’s as the domain to keep things simple, then update the vhost file with this line ServerName The ServerAlias directive is only important when using cname’s so you only need it on the vhost file for the main site in which it would be ServerAlias Then update the corresponding folders in the /var/www/ to mach the names you put in the vhost file and run the command for each of the new sites “a2ensite” replacing the last part for each site of course. Then finally if you have done everything else correctly, you need to restart apache with the following command “service apache2 restart” and then you show be able to go to each of the separate domains in your browser. As a side note when you initially setup the A records and cname it will probably take some time for the DNS to propagate so you might want to take a break for an hour or 2 after that step… <br> <br>Matt