Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have name-based hosting, lets call it my.address.com. My friend has the 'plain' address address.com and gave me a virtual machine that I can access via SSH.

He also made some magic with ports and now, after installing Apache, I could access /var/www through my.address.com.

So, the question is, how can I make a subdomain like test.my.address.com?

There should be some magic with Apache's Listen Directive, but I cant figure it out. Also, I know how to create local-available sites with Apache, but it is not the same.

share|improve this question
You won't need Listen, look at Apaches virtual hosts: httpd.apache.org/docs/2.2/vhosts –  Oliver Salzburg Jul 29 '12 at 11:49
the main question is remained - what to write in ServerName directive? –  scythargon Jul 29 '12 at 12:16

1 Answer 1

up vote 17 down vote accepted

To be able to create subdomains, you'll have to make sure of several things:


So other's can reach test.my.address.com, they first have to be able to resolve that name to the IP address of your virtual machine. How can that be done?

What your friend most likely already did, was to create an A record in the address.com zone, which points my to the IP address of your VM.

So far, so good. But what about test.my? It might not have an entry yet.

Your friend could simply add *.my to the zone as well (and point it to the same IP address). Then all request to something.my.address.com would be send to your VM. Great!

Apache Virtual Hosts

Once your VM can be reached, Apache has to know how to handle the request. This is where we use the Virtual Hosts feature of the Apache HTTP server.

I usually run on Debian, so I'll explain this with an example configuration in /etc/apache2/sites-available. Let's have a file there called test.my.address.com and fill it with information.

<VirtualHost *:80>
        ServerName test.my.address.com
        ServerAdmin webmaster@my.address.com

        DocumentRoot /var/www/test.my.address.com/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        <Directory /var/www/test.my.address.com/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all

        ErrorLog ${APACHE_LOG_DIR}/test.my.address.com.error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/test.my.address.com.access.log combined

The key setting inside this file is the ServerName directive. This tells Apache under which name this server should be available. Additional names can be given with the ServerAlias directive.

In case you're using Debian as well, don't forget to sudo a2ensite test.my.address.com after you created the file and sudo invoke-rc.d apache2 restart.

share|improve this answer
Thanks a lot!:) I made my part, and wrote email to friend about his part. Thank again:) –  scythargon Jul 29 '12 at 12:32
Also, thank for checking my English:) –  scythargon Jul 29 '12 at 12:38
@scythargon: My pleasure. We're here to help :) –  Oliver Salzburg Jul 29 '12 at 12:54
While my friend did not answer my, can you, please? What I was thought about how it works: http-request for test.my.address.com goes to my.address.com and then my Apache server on VM handles it. But you said that DNS-server at address.com should know about test.my before all of this and independently of knowledge about my, why? –  scythargon Jul 29 '12 at 13:07
@scythargon: For any HTTP request to reach your server, any client first has to figure out to what server the request has to be sent. So the hostname has to be valid. Otherwise they'll just be told "that name does not exist". –  Oliver Salzburg Jul 29 '12 at 13:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.