Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I would like subdomains of my EC2 Instance Public URL to point to different document trees in on my machine so foo.ec2-012-345-678-901.eu-west-1.compute.amazonaws.com has a separate DocumentRoot to bar.ec2-012-345-678-901.eu-west-1.compute.amazonaws.com

My AWS EC2 instance has an elastic IP and a standard Amazon Public URL:

http://ec2-012-345-678-901.eu-west-1.compute.amazonaws.com

I can visit that URL and I see my Hello World test page.

I've set up two VirtualHosts.

<VirtualHost *:80>
  DocumentRoot /var/www/foo/public
  ServerName foo.ec2-012-345-678-901.eu-west-1.compute.amazonaws.com
  ServerAlias ec2-012-345-678-901.eu-west-1.compute.amazonaws.com
</VirtualHost>
<VirtualHost *:80>
  DocumentRoot /var/www/bar/public
  ServerName bar.ec2-012-345-678-901.eu-west-1.compute.amazonaws.com
</VirtualHost>

In AWS Route 53 I've set up a hosted zone with the domain name ec2-012-345-678-901.eu-west-1.compute.amazonaws.com

In the record sets I have added two CNAME records:

1)

  • Name: foo.ec2-012-345-678-901.eu-west-1.compute.amazonaws.com
  • TTL: 60
  • Value: ec2-012-345-678-901.eu-west-1.compute.amazonaws.com
  • Routing Policy: Simple
  • Alias: No

2)

  • Name: bar.ec2-012-345-678-901.eu-west-1.compute.amazonaws.com
  • TTL: 60
  • Value: ec2-012-345-678-901.eu-west-1.compute.amazonaws.com
  • Routing Policy: Simple
  • Alias: No

My browser can't find either of the URLs defined in the virtual hosts. I'm using using OpenDNS, but I can SSH into a few other machines and try curl and wget and always receive the error "Name or service not known" or "couldn't resolve host".

I have been playing around with these settings a bit today, but as well as I can remember this is exactly how I set them up 24 hours ago.

What do I need to do to get my virtual hosts to resolve to the directories I've defined?

Note: I'm on RHEL, with SELinux enabled. I don't think it's relevant, but it's been the cause of a few issues already.

Cheers,

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You need to set Apache's ServerName for the virtual host to the actual hostname that you want to serve, such as foo.example.com, and NOT the EC2 internal hostname (though you could use a ServerAlias for that if you wanted it to be accessible).

Unfortunately you can't use your EC2 hostname as a domain within Route 53; you have to use your own domain name.

share|improve this answer
    
Please accept my apologies if I've misunderstood your point, but foo.ec2-012-345-678-901.eu-west-1.compute.amazonaws.com is the actual hostname I want to serve, for now. –  Andrew Martin Nov 27 '12 at 17:15
    
Oh, I see what you're doing. –  Michael Hampton Nov 27 '12 at 17:17
    
Edited for clarity. –  Andrew Martin Nov 27 '12 at 17:20

I would like subdomains of my EC2 Instance Public URL to point to different document trees in on my machine so foo.ec2-012-345-678-901.eu-west-1.compute.amazonaws.com has a separate DocumentRoot to bar.ec2-012-345-678-901.eu-west-1.compute.amazonaws.com

I just checked a few of my instances, and Amazon does not wildcard an instances public URL.

ec2-012-345-678-901.eu-west-1.compute.amazonaws.com will work, but *.ec2-012-345-678-901.eu-west-1.compute.amazonaws.com will not.

In AWS Route 53 I've set up a hosted zone with the domain name ec2-012-345-678-901.eu-west-1.compute.amazonaws.com

This won't work either. You can set up all the records you like, but no ones's going to see them, as Amazon isn't delegating the subdomain to your Route53 zone.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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