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.

  • @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

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.

| improve this answer | |
  • 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 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: <VirtualHost *:80> DocumentRoot /var/www/html/demo/complete ServerName demo.example.com </VirtualHost> – jonmrich Jan 29 '15 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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