2

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,

2 Answers 2

2

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.

5
  • 1
    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. Nov 27, 2012 at 17:15
  • Oh, I see what you're doing. Nov 27, 2012 at 17:17
  • Edited for clarity. Nov 27, 2012 at 17:20
  • you can't use your EC2 hostname as a domain within Route 53. 1) Why? 2) How do you know that? 3) Could you plz provide a link for official AWS documentation on that?
    – Green
    Oct 11, 2016 at 20:33
  • 1
    @Green I would like to invite you to try to set up amazonaws.com as a hosted domain in Route 53, and see what happens. Oct 11, 2016 at 20:34
1

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.

2
  • Amazon isn't delegating the subdomain to your Route53 zone. 1) Why? 2) How do you know that? 3) Could you plz provide a link for official AWS documentation on that?
    – Green
    Oct 11, 2016 at 20:34
  • @Green 1) I don't know, ask Amazon. 2) Because dig ns <ec2 public hostname> returns no results. 3) No, because AWS documentation doesn't provide a comprehensive list of features they don't have anywhere, and also because 2).
    – ceejayoz
    Oct 11, 2016 at 21:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .