I have a domain name called dumbdom.com. I have an elastic IP for my AWS EC2 instance called my.ela.stic.ip. The htdocs root of my linux based EC2 instance is at /var/www/html/.

I have set up the /etc/httpd/conf.d/vhost.conf file to direct the domain dumbdom.com to /var/www/html/my_dumb_app/ and that's working Fine! The vhost.conf file looks like this:

NameVirtualHost *
<VirtualHost *> 
   ServerName dumbdom.com
   DocumentRoot /var/www/html/my_dumb_app
<VirtualHost *> 
    ServerName blog.dumbdom.com
    DocumentRoot /var/www/html/my_blog_directory

Now, I want dumbdom.com & blog.dumbdom.com to keep landing on to /var/www/html/my_dumb_app/ & /var/www/html/my_blog_directory respectively; and i also want everything else via my.ela.stic.ip address to simply go to /var/www/html like normal. So that going to dumbdom.com and going to my.ela.stic.ip/my_dumb_app would end up landing at the same location.

It just so happens that since my vhost.conf file has <VirtualHost> tags for dumbdom.com & blog.dumbdom.com, trying to reach other directories of the server through the elastic_ip causes a 404-NotFound error.



As per http://httpd.apache.org/docs/2.2/vhosts/name-based.html, you can create a VirtualHost entry for the IP address.

So you'll have something like

<VirtualHost my.elas.stic.ip>
   ServerName my.elas.stic.ip
   DocumentRoot /var/www/html

Also be aware that the first vhost declaration is the default - this probably won't affect you, but anyone accessing your instance via the instance external IP, or the EC2 instance domain name will get whatever comes first.

Edit: There are several ways to access your EC2 instance. First off, every instance has both public and private IP addresses, as well as public and private DNS entries. Accessing the instance via one of these (i.e. ec2-x.x.x.x.y.amazonaws.com) will not match up with any of the host names, so will pick the default. When you restart in instance, and before you re-assign the elastic IP address, the same will happen for the external IP address.

  • thanks @chris. this worked for me. However, could you please clarify the implications of the first vhost declaration being the default part? I didn't quite get that. – Rakib Dec 24 '12 at 16:12

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.