I have the following VirtualHost
// filename: /etc/apache2/sites-available/ccbbbcc
<VirtualHost 1.1.1.1:80>
ServerAdmin [email protected]
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
</VirtualHost>
And then I also have
//filename: /etc/apache2/sites-available/default
<VirtualHost 1.1.1.1:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
blah blah blah
How come when I type into my browser http://1.1.1.1, it takes me to http://ccbbbcc.com ? Even when I point new urls to the IP 1.1.1.1, 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
NameVirtualHost 1.1.1.1:80
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 http://1.1.1.1/test.html, I get a 404 Page Not Found. When I type http://1.1.1.1/, 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 http://1.1.1.1 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:
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.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 1.1.1.1:80 directive, the virtual host isn't Name-Based, it's address:port based.
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.