I have several web sites, all set up in http-vhosts.conf with their respective ServerName and DocumentRoot, they are working fine and dandy.

But when I visit the server's IP address URL, I get back the files in the first virtual host, rather than Apache serving from where I would expect, the http.conf file's DocumentRoot.

How can I configure Apache so visiting the server by IP address, whether external or loopback, does not return the first VirtualHost?

Here's the first VirtualHost, which I'm currently getting back as the response if I visit the web server by IP:

<VirtualHost *:80>
    ServerName "delaneatallent.com"
    ServerAlias "www.delaneatallent.com"
    DocumentRoot "/Library/WebServer/Documents/delanea"

Using Apache 2.2.14 on OS X, if that matters.



In short, you can't - that's how Apache works. If you are listening on that IP (as per Prix's comment) then Apache will use the first virtual host as defined when serving up an IP request.

If this is undesirable, then consider changing the first virtual host to be what you actually want served if it's by IP. If that is not what you want, then consider putting in redirect as the first virtual host to make it go somewhere you do want.

# default
<VirtualHost *:80>
  RewriteEngine on
  RewriteRule ^/(.*) http://othersite.com/$1 [L,R]

You can't stop Apache from listening on that IP, but you can make it do something else that does do what you want with a little creativity.

  • Thanks Troy! I didn't want to create a fake VirtualHost as a patch if the cause was something else in my config. Works fine now. – richardtallent Aug 29 '10 at 4:56

What I did to remedy this was to do a default page for /var/www and that serves the default site you see when you navigate to my server by IP or unknown url related to a site on my server.

The actual sites that I host are in the sites-enabled folder with the default site configuration, all name based and pointing to a different directory.

Long story short, navigate to my server by its IP, you get the default error page.


To make your apache listen to specific ip and port you must define it:


Where and are 2 example ips i have assigned to it.

If you already have another Listen configured you may need to change it, for example:


would make your apache listen on all interfaces available.

  • Listen is set to "80", server is serving files fine. Problem is that when visiting the site by IP address, the first VirtualHost is returned rather than the expected DocumentRoot. – richardtallent Aug 28 '10 at 18:02
  • that is how apache works it will always show the documentroot for the 1st virtualhost. if u dont want that you can create a new 1st virtualhost there is nothing you can really do about it. For example if u listen to 2 ips when those 2 ips are typed they will take you to the document root. – Prix Aug 28 '10 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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