Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have name-based hosting, lets call it My friend has the 'plain' address 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

So, the question is, how can I make a subdomain like

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: – 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
up vote 21 down vote accepted

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


So other's can reach, 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 zone, which points my to the IP address of your VM.

So far, so good. But what about 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 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 and fill it with information.

<VirtualHost *:80>

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

        ErrorLog ${APACHE_LOG_DIR}/

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

        CustomLog ${APACHE_LOG_DIR}/ 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 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 goes to and then my Apache server on VM handles it. But you said that DNS-server at should know about 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .