Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an Apache2 server setup with several vhosts, and it all works fine. Navigating to my ip renders one of those vhosts (/etc/apache2/sites-enabled/, which--up until now--I had wanted.

Now I want the ip to go to the default vhost /etc/apache2/sites-enabled/default, but I can't remember where to change that. I assume there's some directive in /etc/apache2/apache2.conf, but nothing is sticking out at me.

Any help would be appreciated.

➜ /etc/apache2: ls sites-enabled/  

➜ /etc/apache2/sites-enabled: cat default
NameVirtualHost *
<VirtualHost *>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined
    ServerSignature Email

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from ::1/128


/etc/apache2/apache2.conf =>

➜ /etc/apache2/sites-enabled: cat
<VirtualHost *:80>

        # ...

share|improve this question
Naked IP ... as opposed to an IP wearing a pair of casual slacks? – Hyppy Jun 9 '11 at 16:26
can you please show your /etc/apache2/sites-enabled/default? – Hameedullah Khan Jun 9 '11 at 16:30
@Hyppy Haha! Yes, I only deal with pantless IPs. Standard procedure. :) – neezer Jun 9 '11 at 16:34
@Hameedullah Khan - Added to the post; take a look. – neezer Jun 9 '11 at 16:51
Eveything else looks fine, can you please also show the output of "apache2ctl -t -D DUMP_VHOSTS" – Hameedullah Khan Jun 9 '11 at 17:06
up vote 2 down vote accepted

You have in your /etc/apache2/apache2.conf:

# Include the virtual host configurations:
Include /etc/apache2/sites-enabled/

ServerName main_site
DocumentRoot /var/www

NameVirtualHost *:80

Move NameVirtualHost before Inlcuding virutal hosts configurations. It should be like following:

NameVirtualHost *:80

# Include the virtual host configurations:
Include /etc/apache2/sites-enabled/

Also you don't need the NameVirtualHost * in your default virtual host file.

share|improve this answer
+1. Good catch. – Kyle Smith Jun 9 '11 at 17:18

The first VirtualHost that's loaded with that IP:Port pair will be used to render requests which do not contain a host header. Make sure your virtualhosts clearly use the IP address or *, and the port #. Now, I believe the files in sites-enabled are loaded in alphabetical order, which would mean that the default file should take precedence over the main_site file.

Post your VirtualHost and we can take a look.

share|improve this answer
Added to the post; take a look. – neezer Jun 9 '11 at 16:50
Stab in the dark: Apache may prefer the more-specific default. Your VHost in your main_site is *:80, which specifies a port, while your default is even-more-vague. I personally specify full IP:PORT in all my VirtualHosts, but you may want to try upping the default to a matching *:80 and see if that helps. – Kyle Smith Jun 9 '11 at 17:07

You've likely got a ServerName or ServerAlias directive that specifies the IP address in main_site, or the <VirtualHost> block specifically specifies the IP to listen on (instead of *:80; which is probably disabling name-based vhosting completely).

If there's no matching ServerName or ServerAlias, and the vhosts are all set to a listener specification that matches your NameVirtualHost directive, then the first vhost to load (alphabetically) will serve the request. That's not happening, so one of those two things must be off.

share|improve this answer
Shane, I'm pretty sure you can use name-based virtual hosting while specifying an IP address in the VirtualHost directive, so long as you turn on name-based for that IP:Port pair with the NameVirtualHost directive. – Kyle Smith Jun 9 '11 at 16:32
Doesn't look like either of those things are happening, since all my vhosts are setup to listen on *:80 (which matches the NameVirtualHost directive), and alphabetically default is still not loading... ?? – neezer Jun 9 '11 at 16:54
@Kyle Absolutely - I just tend to skip over that and assume that the only NameVirtualHost directive that most people have set is *:80. @neezer Anything in the error log that might be indicating that the default file isn't loading? – Shane Madden Jun 9 '11 at 17:20
take a look at the accepted answer. I think this makes sense. – Kyle Smith Jun 9 '11 at 17:31

Put the site that you want to respond per default first in the list.

On Ubuntu/Debian:

rm /etc/apache2/sites-enabled/default
ln -s /etc/apache2/sites-available/default /etc/apache2/sites-enabled/00default

(or another site, if you want it to be the default)

share|improve this answer

Your Answer


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.