0

I've tried to follow a few different tutorials on this, but can't quite get it to work.

I have all of my DNS for my domain (example.com) in Route 53. Works fine.

My top level domain (A record) points to my load balancer (AWS) as an alias. This points to an EC2 server and works fine.

I want to add a subdomain (client.example.com), but I'm not quite sure where to add this and what type of records I need. I want this to point to a directory on the same EC2 server as my top level domain (which would have the path example.com/client). I don't want it to redirect, just serve the files from this directory.

Not sure if I need to create a new hosted zone or not, what to put in the zone, what to point it at, and if I need to modify anything on my server (like a rewriterule).

Any direction would be appreciated.

jonmrich
  • 185
  • 1
  • 8
  • @EEAA I tried adding a CNAME record that pointed the sub (demo.example.com) to a specific directory (example.com/demo) and then tried to add a virtualhost for demo.example.com with a redirect rule to example.com/demo, but this didn't work. – jonmrich Jan 29 '15 at 14:33

1 Answers1

1

I havent worked with much AWS, but the general way of doing it will be as follows.

Let say currently you have example.com hosted in Route53, so Route53 is the authoritative nameserver for your example.com zone. Now if you want a subdomain called client.example.com which again needs to point to the same IP address where example.com.

So in that case create a CNAME record where example.com will be canonical name and client.example.com will be alias record.

Once this is done now example.com and client.example.com will both resolve to the same IP address i.e to the Load balancer.

If you prefer to share the same DocumentRoot of example.com to client.example.com you have noting extra to do. But if you want to serve different content then create a Name-Based Virtual host in Apache.

Update

As you want both demo.example.com and example.com to serve different contents you have to create a Name-Based virtual host in Apache.

The configuration will be looking like

<VirtualHost *:80>
     ServerName example.com
     ServerAlias www.example.com
     DocumentRoot /var/www/main
</VirtualHost>

<VirtualHost *:80>
     ServerName demo.example.com
     DocumentRoot /var/www/content
</VirtualHost>

The above configuration will serve file from /var/www/main if request is for http://example.com or http://www.example.com. And it will serve files from /var/www/content if the request is for http://demo.example.com.

Kannan Mohan
  • 603
  • 4
  • 6
  • I get the first part...what I want is to have some content that is only available via the subdomain. Let's say this is stored in a directory called `content`. So, only `demo.example.com` should be able to point to `content`. You can't get to it from example.com/content. How can I do this? How do I "tell" the DNS to point the subdomain to a specific directory? I don't want demo.example.com to point to the top level directory in example.com, but rather to a specific directory within example.com (e.g., `content`) – jonmrich Jan 29 '15 at 14:31
  • DNS does not point to anything other than an IP address. Anything else needs to be handled in the http layer. – EEAA Jan 29 '15 at 14:35
  • @jonmrich I have updated my answer based on your comment. – Kannan Mohan Jan 29 '15 at 14:44
  • @jonmrich [this](http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/CreatingNewSubdomain.html) document can help you with adding subdomains in Route53. – Kannan Mohan Jan 29 '15 at 14:46
  • @KannanMohan Thanks for the update I don't think I'm doing this quite right. I created a new DNS CNAME record the name is demo.example.com and the value is example.com. I added a virtual host entry as you suggested with the different folder roots. What's happening is that demo.example.com is still serving files from my main directory (as if the virtual host is ignored). My virtual host entry for the subdomain looks like this: ` DocumentRoot /var/www/html/demo/complete ServerName demo.example.com ` – jonmrich Jan 29 '15 at 16:06
  • @jonmrich The `VirtualHost` configuration looks good. If you are using Linux can you try `curl -L http://example.com` and `curl -L http://demo.example.com`. If both the outputs are same and from `example.com`, try `curl -L http://demo.example.com -H 'Host: demo.example.com'` and paste these outputs in your question section. – Kannan Mohan Jan 29 '15 at 16:55
  • I ran all those commands and it spits out all of the HTML from my page. It is all for the same page, which is my index.html file in the top level directory of the domain. It also has this at the top:`curl: (6) Could not resolve host: -L` This is for the last curl statement you provided – jonmrich Jan 29 '15 at 17:44
  • Is both `example.com` and `demo.example.com` resolving ? Try `dig example.com +short` and `dig demo.example.com +short`. Both should return the same IP – Kannan Mohan Jan 30 '15 at 02:01