I have an Amazon ec2 instance with a static public IP and a public domain name assigned by Amazon (ec2-my-hosts-public-ip.compute-1.amazonaws.com. Let's call it ec2.amazon.com).

I have a domain name, example.com. In my DNS, I have example.com forward to point to www.example.com.

www.example.com has an A name record pointing to my ec2 instance's public IP.

On my ec2 instance, I have two web folders: /var/www, and /var/www-public. Apache vhosts are set up to point www.example.com at /var/www-public. By default, vhosts point ec2.amazon.com at /var/www. Enjoy this little table:

www.example.com --> /var/www-public
ec2.amazon.com  --> /var/www

I wanted a shorter alias for my ec2.amazon.com address (remember, it's really ec2-my-hosts-public-ip.compute-1.amazonaws.com), so I set up a CNAME record to point ec2.example.com at ec2.amazon.com:

ec2.example.com CNAME ec2.amazon.com

However, I ran into a problem. Many (possible all?) DNS setups will respond to a request for ec2.example.com by simply returning the IP address of ec2.amazon.com as if it had just found an A name record, and the client won't be able to tell that an alias was involved. This is a problem because then the HTTP request that the browser sends to my server lists the domain as "ec2.example.com" rather than "ec2.amazon.com," and my server has no vhost set up for ec2.example.com, so it just defaults to the wrong page.

For reasons that are not really important, I can't alter this apache configuration. Using only DNS records, is it possible for me to remedy this? An ideal solution would be for the client (most likely a browser) to be somehow informed of this aliasing so that it could send "ec2.amazon.com" in its HTTP request header. Basically, I want it to act like a DNS forward rather than a normal CNAME. I initially thought that PTR records looked promising, since, according to Wikipedia, "Unlike a CNAME, DNS processing does NOT proceed, just the name is returned," which is exactly what I wanted (at least, the name being returned part), but I later discovered that PTR records are only associated to IP addresses for reverse-DNS.

1 Answer 1


Browsers talk to IP address, not domain name. But to target the good domain, they pass a header "Host: ec2.amazon.com", and this value is generally what appears in the address bar (or hidden in iframe). If you can't configure your vhost with the name ec2.example.com, then what you should do is redirect it to longaddress.amazon.com, or embedding longaddress.amazon.com in an iframe. It's a simple redirection that don't necessarily involve DNS setup and for which CNAME is not the solution.

So, you have to host ec2.example.com where you can, and the page should contains frames to include longaddress.amazon.com, or, page should redirect (Meta or Location: header) to longaddress.

  • That's possible, but I'd like to do this through DNS if at all possible. I know that forwarding is possible, but I don't know how. My DNS registrar only allows forwarding from the base domain (in my case, I forward example.com to www.example.com). This does work, in that when I go to "example.com" in my browser, it changes the url to "www.example.com," but my registrar won't let me forward ec2.example.com
    – joshlf
    Feb 7, 2013 at 15:02
  • So, you have to host ec2.example.com where you can I meant, you assign this subdomain to any server you have (using CNAME or A). But on that server, you must have the ability to configure vhost with then mane ec2.example.com. You can take any free webhosting for that. So, request to ec2.example.com would go to that server, where you perform the redirection to longaddress. Redirection from example.com to www.example.com works, but not through DNS, but rather through the webserver configuration.
    – DotMG
    Feb 8, 2013 at 6:10
  • If the redirection doesn't work through DNS, then how is it that I set up that redirection through my DNS registrar? Isn't anything I set up through my registrar guaranteed to be accomplished using DNS in some way? Or do they point example.com at their own servers which perform an http redirect or something?
    – joshlf
    Feb 8, 2013 at 21:26
  • Yes, they point example.com at their own servers which then perform http redirect.
    – DotMG
    Feb 12, 2013 at 21:15
  • Oh, cool. I totally didn't know that (and curl confirms :D)
    – joshlf
    Feb 12, 2013 at 23:11

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.