MacOS – Virtual Hosts Not Working on OSX Mavericks

apachemacoswebserver

In Mac OS X 10.9.3 I've Included http-vhosts in httpd.conf

# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

I've commented out the DocumentRoot and the Directory in httpd.conf

# DocumentRoot "/Library/WebServer/Documents"
# <Directory "/Library/WebServer/Documents">...</Directory>

I've added the following to my httpd-vhosts.conf file

<VirtualHost *.80>
    DocumentRoot /Users/gdboling/Sites/rocket-gen
    ServerName local.rocket-gen.com
    <Directory "/Users/gdboling/Sites/rocket-gen">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

And I've added the following to my /etc/hosts file

127.0.0.1    local.rocket-gen.com

I've restarted Apache

sudo apachectl restart

There is an index.html in that directory but when I access http://local.rocket-gen.com from the browser I get a 404. I am getting this in the error logs

[Tue Jun 17 19:09:10 2014] [error] [client 127.0.0.1] File does not exist: /usr/htdocs

I can't figure out why it is not working. If I create that directory as the DocumentRoot in httpd.conf it works. But I need to have several Virtual Hosts, so I'd like to get the vhosts file to work.

Best Answer

It looks like you have nearly everything correct. I'm running Mavericks with a couple dozen virtual hosts, so this should work for you.

First, and this might be all you need to do to fix things, you need to enclose your DocumentRoot in quotes. So,

DocumentRoot /Users/gdboling/Sites/rocket-gen

becomes

DocumentRoot "/Users/gdboling/Sites/rocket-gen"

Next, add the following to your /etc/hosts file, on the line immediately following what you already have. Your hosts file should be:

You have this part:

127.0.0.1    local.rocket-gen.com

Now add this right below:

::1     local.rocket-gen.com

I have each of my vhosts set in hosts this way.