I'm trying to set up two virtual hosts. Here's my httpd config:
<Directory /Users/userX/dev/sandbox-2>
Order deny,allow
deny from All
Allow from localhost
</Directory>
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
DocumentRoot "/Users/userX/dev/sandbox-2"
ServerName blah
</VirtualHost>
<VirtualHost 127.0.0.1>
DocumentRoot "/Users/userX/dev/sandbox"
ServerName fooboar
</VirtualHost>
My problem is that, no matter which server name I try to access in my browser (blah or foobar) it'll serve from blah's DocumentRoot. However, if I were to comment out the the VirtualHost for blah, then it'll take me to foobar's DocumentRoot.
I'm running apache2 on a mac osx if that makes a difference.
Thanks!
---------- Post updated 05-25-12 at 04:19 AM ---------- Previous update was 05-24-12 at 09:09 PM ----------
Here's the solution with the help of a member from another forum.
# default container
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/var/www/html"
ServerName localhost
<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>
# Virtual host 1
<VirtualHost *:80>
DocumentRoot "/Users/userX/dev/sandbox"
ServerName foobar
<Directory "/Users/userX/dev/sandbox">
Options Indexes FollowSymlinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
# virtual host 2
<VirtualHost *:80>
DocumentRoot "/Users/userX/dev/sandbox-2"
ServerName blah
<Directory "/Users/userX/dev/sandbox-2">
Options Indexes FollowSymlinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
But regarding about the errors that I had with the config that was posted:
There were multiple issues..
The biggest one is that I had a typo. (I had fooboar, not foobar)
Second, I need to include the port in NameVirtualHost as well as in
Also, what helped a lot while debugging this was start httpd in debug mode which is:
apachectl -e debug