Default Apache Site

I have multiple virtual host setup within Apache, each of which are named virtual. They are all working fine, but if I type only the IP address into the browser, it looks like the server returns the first virtual host listed.

How can I control the default site directory if only IP is entered? I'd like the default page within /var/www/html to open. This is a CentOS 5.3 installation.

Some settings I have are like this:

DocumentRoot "/var/www/html"

…. options …..

NameVirtualHost *:80

ServerAdmin admin@emailaddress.com

DocumentRoot /var/www/website1

ServerName www.website1.com

ServerAlias website1.com

ErrorLog logs/website1-error.log

CustomLog logs/website1-access.log common

ServerAdmin admin@emailaddress.com

DocumentRoot /var/www/website2

ServerName www.website2.com

ServerAlias website2.com

ErrorLog logs/website2-error.log

CustomLog logs/website2-access.log common

3 Replies

Thanks for pointing that out. I should have found it earlier, but for some reason, I missed it.

Bzzt! Wrong!

You're not using per-IP VirtualHosts. default would work then, yes.

You're using NameVirtualHosts.

And in these, the first entry for the IP in question (or the *:80 wildcard, of course) is the one that's used if no ServerName or ServerAlias names equal the Host: header.

TL;DR: With NameVirtualHosts, first entry is default entry.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct