Subdomain using AWS Route 53, load balancer, EC2, Apache

amazon ec2amazon-route53amazon-web-servicesapache-2.2

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.

Best Answer

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.