I have the following VirtualHost

// filename: /etc/apache2/sites-available/ccbbbcc

     ServerAdmin utopia@ccbbbcc.com
     ServerName ccbbbcc.com
     ServerAlias www.ccbbbcc.com
     DocumentRoot /srv/www/ccbbbcc/production/public_html/
     ErrorLog /srv/www/ccbbbcc/production/logs/error.log
     CustomLog /srv/www/ccbbbcc/production/logs/access.log combined

And then I also have

//filename: /etc/apache2/sites-available/default

ServerAdmin webmaster@localhost

        DocumentRoot /var/www/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
blah blah blah

How come when I type into my browser, it takes me to http://ccbbbcc.com ? Even when I point new urls to the IP, webpages serve from http://ccbbbcc.com. Why am I unable to serve pages from /var/www directory?

Additional symptoms - the ccbbbcc vhost overrides only SOME of my other vhosts. Not all.

Additional Notes

I've made sure to use a2ensite and to restart apache.

This is what my /etc/apache2/ports.conf looks like

Listen 80
Listen 443

I made a file called /srv/www/ccbbbcc/production/public_html/test.html with the text "Hello World". When I type http://ccbbbcc.com/test.html, the page loads fine. When I type, I get a 404 Page Not Found. When I type, the web browser refreshes and then displays the url http://ccbbbcc.com. I then append test.html to the end of the url, and the Hello World shows up again.

So does that mean there's an http redirect happening somewhere? If so, I can't seem to determine what's causing it.

Also, i notice ccbbbcc overrides SOME of my virtualhosts, not ALL. There doesn't seem to be a pattern to which vhost is discriminated/overridden.

I also noticed that if I do the following

1. a2dissite ccbbbcc
2. /etc/init.d/apache2 reload
3. a2ensite ccbbbcc
4. /etc/init.d/apache2 reload

Then all of a sudden, http://ccbbbcc.com serves pages from /var/www/, and also serves pages from /var/www. How come the a2ensite/a2dissite of affects where pages are loaded from? The only way to make ccbbbcc serve pages from /srv/www/cbs/production again is to reboot my entire linux server! What's going on?


As you can read in An In-Depth Discussion of Virtual Host Matching:

The first vhost on this list (the first vhost in the config file with the specified IP address) has the highest priority and catches any request to an unknown server name or a request without a Host: header field.

Your Apache httpd loads and evaluates the file /etc/apache2/sites-available/ccbbbcc before /etc/apache2/sites-available/default.

Rename /etc/apache2/sites-available/default for example to /etc/apache2/sites-available/00_default and /etc/apache2/sites-available/ccbbbcc to /etc/apache2/sites-available/01_ccbbbcc, so that the default file is loaded first.

  • Apache has several configuration files, what 'config file' to check for the 'vhost list' in this context? I assume it's "/etc/apache2/sites-available"? – Edwin Yip Nov 6 '12 at 6:41
  • OK, I seem have figured it out, there is a line in my apache3.conf: Include /etc/apache2/sites-enabled/, and when I ls that directory the first item appeared is the fist vhost.... – Edwin Yip Nov 6 '12 at 6:53

Do you have a NameVirtualHost directive?

See here: http://httpd.apache.org/docs/2.0/mod/core.html#namevirtualhost

Basically if you don't have a NameVirtualHost *, or specific NameVirtualHost directive, the virtual host isn't Name-Based, it's address:port based.

  • I have NameVirtualHost Listen 80 Listen 443 in my ports.conf – John Apr 15 '10 at 16:20
  • How are your symlinks in sites-enabled configured? They are sourced alphabetically and I am not sure, but Apache may default to the first VirtualHost directive for the host:port combination. – Kyle Smith Apr 15 '10 at 16:23
  • I'm don't understand the symlinks. How do I check? Also, I think I noticed the alphabetical ordering of VirtualHost file names influencing which host:port combination gets selected. But shouldn't the ServerName property make the selection more specific/filtered? – John Apr 15 '10 at 16:28

Without a ServerName/ServerAlias block in your virtual hosts, apache will serve the domain first instantiated during the config read. In this case, alphabetically, ccbbbccc.com's config file must come before default.

Add ServerName and/or ServerAlias directives in /etc/apache2/sites-enabled/default and you should be set.

  • Thanks, I did this but still no effect. I noticed that under /etc/apache2/sites-enabled/ there's a file called 000-default. Apparently apache automatically renames my default to 000-default to ensure it gets loaded first. – John Apr 15 '10 at 17:41
  • can you post the results of: /usr/sbin/apache2 -S – deleted Apr 17 '10 at 20:22
  • Hmm...I get a "apache2: bad user name ${APACHE_RUN_USER}". What does that mean? – John Apr 18 '10 at 16:28
  • did you install apache from a package? or compile it yourself? After you are making config changes, are you stopping apache, ps ax|grep apache, make sure it is stopped, then restarting it? in your config file, User should correspond to a value, is there a username on your system that corresponds? – deleted Apr 18 '10 at 23:31

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.