Quantcast
Viewing all articles
Browse latest Browse all 10

name-based virtual host – specify a domain name and also leave the ip address open

Image may be NSFW.
Clik here to view.
Question

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>
<VirtualHost *> 
    ServerName blog.dumbdom.com
    DocumentRoot /var/www/html/my_blog_directory
</VirtualHost>

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.

Thanks

Asked by syedrakib

Image may be NSFW.
Clik here to view.
Answer

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
</VirtualHost>

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.

Answered by chris

Viewing all articles
Browse latest Browse all 10

Trending Articles