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.
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?
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/
You need to use your own DNS in order to use subdomains. AWS' DNS doesn't have a wildcard record on their dynamically assigned DNS.
You can try:
dig clients.ec2-123-123-123-123.compute-1.amazonaws.com
and you will receive 0 answers.
As for:
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?
Again, you need a DNS record clienta.staging.mydomain.com pointing to the IP address of the host and then let Apache or whatever server channel those request to the right vhost. But your clienta.staging.mydomain.com
request will never know where to go unless there's an explicit dns entry for it. Some DNS services offer catch-all, wildcard based DNS entries (i.e. *.clients.blah.com
), so that could be an option if supported by your DNS provider.
Another suggestion would be to use directories as opposed to subdomains. So, instead of creating a new subdomain, just have clients.domain.com
DNS entry, then have clients.domain.com/clienta
and clients.domain.com/clientb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With