Monday, March 30, 2009

Apache2 Virtual Hosts Not Working - NameVirtualHost

I encountered this problem while setting up this website. I created 2 virtual hosts in:

- kbomb
- phpmyadmin

kbomb Virtual Host:
DocumentRoot /var/www/kbomb/public_html
ErrorLog /var/log/apache2/­r.log
CustomLog /var/log/apache2/­ ss.log combined

phpmyadmin Virtual Host:
DocumentRoot /usr/share/phpmyadmin
ErrorLog /var/log/apache2/phpmyadmin.kbomb.­
CustomLog /var/log/apache2/phpmyadmin.kbomb.­ combined

Whenever i went to, or i would get the same website.

With a bit of research here is my findings...

Because my debian server has 3 static IP addresses and does routing, Apache2 doesnt know which interface the Virtual Hosts are to work on. You need to define them in /etc/apache2/apache2.conf.

If you want your Virtual Hosts working on just 1 IP Address you would want to enter:


If you would like your Virtual Hosts working on all network interfaces you want to define a wildcard. This is the most practical method unless you want to lock certain network interfaces from viewing your websites.

NameVirtualHost *

I wacked this line at the end of my apache2.conf file just before Include /etc/apache2/sites-enabled/.

So the end of my file looks like:

NameVirtualHost *

# Include the virtual host configurations:
Include /etc/apache2/sites-enabled/

This fixed my problem

No comments:

Post a Comment