Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Originally posted this over at superuser...

Ive configured Apache for Name-based Virtual Hosting but I can't seem to get a local site to show in my browser. Is my httpd.conf misconfigured? Here's the sanitized version:

#
# Use Name-based Virual Hosting.
#
NameVirtualHost *.:80

#
#Set up permissions for VirtualHosts in ~/Sites
#
<Directory "/Users/myusername/Sites">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

# For http://localhost in the OSX default location
<VirtualHost _default_:80>
    ServerName localhost
    DocumentRoot /Library/WebServer/Documents
</VirtualHost>

<VirtualHost *:80>
    ServerName thewebsite.local
    CustomLog "/Users/myusername/Sites/logs/thewebsite.local-access_log" combined
    ErrorLog "/Users/myusername/Sites/logs/thewebsite.local-error_log"
    DocumentRoot "/Users/myusername/Sites/thewebsite.local"
</VirtualHost>

And my etc/hosts

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       thewebsite.local
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost
share|improve this question

1 Answer 1

Apache searches the vhost list from top to bottom and will deliver content from the first virtual host that matches the host header or default whichever comes first. In your configuration the default virtual host is listed first so it's content gets delivered. Put your default site at the end or at least after sites whose content you want delivered.

The NameVirtualHost directive is usually NameVirtualHost *:80. It's generally not a great idea to use .local as it's use by mDNS etc and can get in the way.

share|improve this answer
    
When I change my .conf file it navigates to the /Library/WebServer/Documents folder now. –  Ofeargall Dec 27 '11 at 0:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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