4

I'm using Yosemite with Apache 2.4

/private/etc/apache2/httpd.conf

ServerName 127.0.0.1:80
DocumentRoot "/Library/WebServer/Documents/"
<Directory "/Library/WebServer/Documents">
    Options Multiviews FollowSymLinks
    MultiviewsMatch Any
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Everything is fine, http://localhost directs me to the default /Library/WebServer/Documents/index.html

After adding Include /private/etc/apache2/extra/httpd-vhosts.conf to /private/etc/apache2/httpd.conf

And adding the config below to /private/etc/apache2/extra/httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName xxx.local
    DocumentRoot "/Library/WebServer/Documents/xxx"
    <Directory "/Library/WebServer/Documents/xxx/">
        Options +FollowSymLinks
        AllowOverride all
        Require all granted
    </Directory>
</VirtualHost>

When using http://localhost and http://127.0.0.1 from the browser, Apache directs me to /Library/WebServer/Documents/xxx/index.html instead of /Library/WebServer/Documents/index.html, how can I fix it?, please guide.

Thanks.

5
  • What do you mean "fix it"? This is completely expected behaviour... Why not just change the DocumentRoot to /Library/WebServer/Documents if that's what you want? Commented Oct 28, 2014 at 14:35
  • I'm sorry, I missed out DocumentRoot "/Library/WebServer/Documents/" it's already there in the file httpd.conf, but I still have this problem Commented Oct 28, 2014 at 15:15
  • But now your DocumentRoot is /Library/WebServer/Documents/xxx instead of /Library/WebServer/Documents/ so obviously the problem remains. Commented Oct 28, 2014 at 15:23
  • @arco444 that's right, actually DocumentRoot has been there but I just forgot to mention in the post, http://localhost directs to the path specified in VirtualHost's DocumentRoot Commented Oct 28, 2014 at 15:42
  • Why don't you just remove the included httpd-vhosts.conf file if that's not where you want the DocumentRoot to be? Once you define a VirtualHost it will take precedence over default settings. Commented Oct 28, 2014 at 15:48

1 Answer 1

6

I had the same problem today.

I found solution here: httpd.apache.org/docs/current/vhosts/name-based.html.

Main host goes away

Any request that doesn't match an existing is handled by the global server configuration, regardless of the hostname or ServerName.

When you add a name-based virtual host to an existing server, and the virtual host arguments match preexisting IP and port combinations, requests will now be handled by an explicit virtual host. In this case, it's usually wise to create a default virtual host with a ServerName matching that of the base server. New domains on the same interface and port, but requiring separate configurations, can then be added as subsequent (non-default) virtual hosts.

Sign up to request clarification or add additional context in comments.

1 Comment

I meant, my requirement is I like to maintain both http://localhost and http://127.0.0.1 to access the global DocumentRoot which is /Library/WebServer/Documents/ and http://xxx.local to access /Library/WebServer/Documents/xxx/ Is this similar to what problem you used to face, and already solved it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.