Amazon-web-services – Use Subdomain with Amazon EC2 Public DNS Address

amazon ec2amazon-web-servicesapachedns

I'm trying to do some testing with a legacy application that relies on subdomains for clients. So in the real application, you could go to:

clienta.domain.com

And it will open a specific area for Client A.

With EC2, I'm trying to get the application to work only using the Public DNS address which looks similar to this:

ec2-123-123-123-123.compute-1.amazonaws.com

The problem is, setting up my vhosts (like this post), works fine for the main Public DNS address, but will not work with a subdomain.

clienta.ec2-123-123-123-123.compute-1.amazonaws.com => DOES NOT WORK

I imagine this is because a DNS CNAME record must also be created? I obviously do not own amazonaws.com so do not have the ability to do that.

Here is the vhost setup:

NameVirtualHost *:80

# Primary domain
<VirtualHost *:80>
    DocumentRoot "/var/www/vhosts/myapp"
    ServerName ec2-123-123-123-123.compute-1.amazonaws.com
    <Directory "/var/www/vhosts/myapp">
            Options Indexes MultiViews FollowSymLinks
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>
</VirtualHost>

# Wildcard Sub Domains
<VirtualHost *:80>
    DocumentRoot "/var/www/vhosts/myapp"
    ServerName clients.ec2-123-123-123-123.compute-1.amazonaws.com
    ServerAlias *.ec2-123-123-123-123.compute-1.amazonaws.com
    <Directory "/var/www/vhosts/myapp">
            Options Indexes MultiViews FollowSymLinks
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>

TL;DR; Without messing with DNS, is there a simple way to use subdomains with the Amazon EC2 Public DNS Address?

NOTE: I'm trying to avoid adding records to our DNS that will only be used for a short time.

UPDATE

If I must use my own domain, how can I work around two subdomains? For example, if I create staging.mydomain.com to point to the EC2 instance, now how would I access clienta.staging.mydomain.com?

Best Answer

Why are you not using your own domain name? Most web services based on EC2 do not use the EC2 public DNS, because that public DNS is likely to change.

What you probably want to investigate is using Elastic IP's so as to give your instances stable IP addresses that you can configure DNS against, then attach these Elastic IP's to your EC2 instances.

Here is the AWS documentation on Elastic IP's: http://aws.amazon.com/articles/1346

Of course, if you plan on using a load balanced configuration, then you would actually use Elastic Load Balancer rather than Elastic IP's. In this configuration, your DNS would direct to the ELB.

Here is information on Elastic Load Balancing: http://aws.amazon.com/elasticloadbalancing/

Related Topic