I've had VHosts working on my OSX client for quite some time. Recently, I've been trying to use http://localhost to access the /Library/WebServer/Documents but it keeps redirecting my to my blog. Can anyone point me in the direction where I might be going wrong?

Here is my hosts file:

127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost 

127.0.0.1 www.chrislrobinson.co.uk
127.0.0.1 blog.chrislrobinson.co.uk

And here is my httpd.conf file:

...
ServerName localhost:80
DocumentRoot "/Library/WebServer/Documents"
<Directory />
   Options FollowSymLinks
   AllowOverride None
   Order deny,allow
   Deny from all
</Directory>
<Directory "/Library/WebServer/Documents">
   Options Indexes FollowSymLinks MultiViews
   AllowOverride All
   Order allow,deny
   Allow from all
</Directory>

And finally here is my httpd-vhosts.conf

<Directory /Library/WebServer/Documents>
    Options Indexes FollowSymlinks MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

<Directory /Library/WebServer/Documents/blog>
    Options Indexes FollowSymlinks MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

<Directory /Library/WebServer/Documents/chrislrobinson>
    Options Indexes FollowSymlinks MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

NameVirtualHost *:80

<VirtualHost 127.0.0.1>
    DocumentRoot "/Library/WebServer/Documents"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents/blog"
    ServerName blog.chrislrobinson.co.uk
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents/chrislrobinson"
    ServerName www.chrislrobinson.co.uk
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents
    ServerName www2.chrislrobinson.co.uk
</VirtualHost>
link|improve this question
feedback

1 Answer

up vote 1 down vote accepted

Change your host specification on the localhost block; it needs to match the NameVirtualHost directive. (There should be a warning in your error log when apache starts about this)

<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents"
    ServerName localhost
</VirtualHost>

Since having it on your default port listener will probably be exposing it to the internet (only with a host header of localhost, but still..), consider locking it down, too:

Order deny,allow
Deny from all
Allow from 127.0.0.1
link|improve this answer
Thank you! I'm sure I had tried that combination but I guess I had something else going wrong with it! – Chris Robinson May 10 '11 at 21:35
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.