Oct 4, 2011
tom

Almost All apache VHOSTs go to the default “It Works Site”

Question

First off I am running Ubuntu 11.04. I installed Apache through tasksel along with phpmyadmin, and mysql. My localhost site works and I can get into phpmyadmin. I have 5 sites setup through VHOST files. I can access 3 of them without any problems.

My problem is there are 2 other VHOSTs that I cannot access the actual site from the browser. Instead it always shows the Default “It works” page. These latest 2 sites are my new sites so I havnt figured this out since adding my fourth site to work on. The first 3 sites for some reason work and I can access the sites through the browser.

Here is what my /etc/hosts file looks like.

127.0.0.1 my.dev

127.0.1.1 systemcrashed

127.0.0.1 dev.bac

127.0.0.1 vl.dev

127.0.0.1 manager.dev

127.0.0.1 pw.dev

The sites that I cannot get working are my.dev and dev.bac. my.dev was the fourth site to add a VHOST file for and recently I just added dev.bac again to try to setup another site I need.

After creating both the VHOST files I ran a2ensite my.dev to enable the site. I have checked the mod_rewrite for apache to see if it was enabled. After running a2enmod rewrite, I get the message mod-rewrite is already enabled.

Here is what my VHOST for both the sites that do not work. (Besides the paths are different)

<VirtualHost *:80>    ServerName dev.back
    DocumentRoot /home/developmental/workspace/dev.bac/public    <Directory /home/developmental/workspace/dev.bac/public>
            AllowOverride All
            Options All
            Order allow,deny
            Allow from all
    </Directory>
</VirtualHost>

If it makes a difference (which i don’t think is does, but trying to give all relevant information) I use the Zend Framework on my projects. So the root of any site starts in the public folder. I have also ensured that there is an .htaccess file residing inside the public folder as well.

[Edited showing /usr/sbin/apache2ctl -S]

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
     default server localhost (/etc/apache2/sites-enabled/000-default:1)
     port 80 namevhost localhost (/etc/apache2/sites-enabled/000-default:1)
     port 80 namevhost dev.bac (/etc/apache2/sites-enabled/dev.bac:1)
     port 80 namevhost manager.dev (/etc/apache2/sites-enabled/manager.dev:1)
     port 80 namevhost pw.dev (/etc/apache2/sites-enabled/pw.dev:1)
     port 80 namevhost my.dev (/etc/apache2/sites-enabled/my.dev:1)
     port 80 namevhost vl.dev (/etc/apache2/sites-enabled/vl.dev:1)
Syntax OK

Answer

I don’t know if it is typo, but in your /etc/hosts you have:

127.0.0.1 dev.bac

and in the virtual host configuration you have:

ServerName dev.back

Then, is normal that your apache redirect you to the wrong place.

Related posts:

  1. Apache isn’t respecting the ServerName directive for a particular site
  2. Apache virtualhost: requests to domain are served from default directory
  3. Understanding vhosts settings
  4. Apache Named VirtualHosts with wildcards
  5. Apache site disabled still serving

Leave a comment