Server Fault is a question and answer site for system and network administrators. 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 am trying to setup subdomains for my AWS EC2 ubuntu instance, but without enough knowledge I couldn't proceed anymore.

  1. I have a parked domain name on a domain name service provider.
  2. My EC2 instance has Elastic IP associated, say
  3. I created two A Recoards in the domain name service provider's website. points to points to

  4. everything is working like a charm , i can access my Instance with the domain name.

But now I would like to have subdomain for individual websites/services for the instance, say,

I tried to setup Virtual Host file for sub-domains, but it didn't work when I accessed those subdomains , chrome said "Oops! Google Chrome could not find"

Q: My question is, how can I set up subdomains for my server?

Thanks in advance.

share|improve this question
it should work with name based virtual hosting in apache , please provide your apache config file. – Abhishek Anand Amralkar May 25 '13 at 5:11
one quick question have you created A record in DNS for your other subdomain pointing to ip – Abhishek Anand Amralkar May 25 '13 at 5:16
HI Abhishek, i haven't created any subdomain Records in DNS. Is it necessary to do it? If I have 100+ subdomains, do i have to add them on the the DNS records? thanks – Chung May 25 '13 at 5:18
yes you need to add A record for each and every subdomain in your DNS in order to access your website publically with Domain name. – Abhishek Anand Amralkar May 25 '13 at 5:20
up vote 5 down vote accepted

By far the easiest way to do this is to create a wildcard DNS record for for example

* 14400 A

or a CNAME


Remember that Apache will serve the content of the first vhost whose ServerName or Serveralias matched the Host: header in the http request. If none of these match then the content of the first vhost defined is served as it is considered the default vhost.

To get apache to server content the easiest way is to use NameBasedVirtual hosting.

If you want to server the same content from each vhost then just define one

NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot /var/www/html

If you want to serve different (but the same) content from and then you could do something line this

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot /var/www/sub1sub2

<VirtualHost *:80>
    DocumentRoot /var/www/html

and so on.

If you have many of vhosts to setup and configure you may want to have a look at Apache's Dynamically configured mass hosting documentation.

share|improve this answer

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.