Can't get virtual hosting working on Apache2

I’m trying to set up two web sites on my Apache2 server using virtual hosting. I created DNS domain zones for both sites. When I point my browser to either domain name, I get the Apache2 default index.html file.

I want to get one site set up correctly, then add the second one. I

I looked at several online tutorials, and finally settled on the approach described at: http://www.debian-administration.org/articles/412 :

I’m running Debian Etch. I’ll create both sites in the /var/www/ directory. The first domain name is bookgenius.org, so I created these directories:

/var/www/bookgenius.com/html

/var/www/bookgenius.com/hcgi-bin

/var/www/bookgenius.com/logs

I opened the file /etc/apache2/sites-available/default

and commented out the first line containing

NameVirtualHost *

(This was per the advice of the tutorial, which notes that when apache starts up, it reads the contents of all files included in /etc/apache2/conf.d.

Next, I created a virtual.conf file in /etc/apache2/conf.d/

containing just the line:

NameVirtualHost *

Then I created a file called /etc/apache2/sites-available/bookgenius.org containing the following:

#

# Admin email, Server Name (domain name) and any aliases

ServerAdmin morgan@acm.org

ServerName bookgenius.org

ServerAlias www.bookgenius.org

Index file and Document Root (where the public files are located)

DirectoryIndex index.html

DocumentRoot /var/www/bookgenius.org/html/

CGI Directory

ScriptAlias /cgi-bin/ /var/www/bookgenius.org/cgi-bin/

Options +ExecCGI

Custom log file locations

LogLevel warn

ErrorLog /var/www/bookgenius.org/logs/error.log

CustomLog /var/www/bookgenius.org/logs/access.log combined

#

Lastly, I typed:

a2ensite bookgenius.org

and got:

Site bookgenius.org installed; run /etc/init.d/apache2 reload to enable.

I reloaded Apache, but the browser still points to the default Apache index.html page instead of the new index.html page I put in the bookgenius.org/html directory.

Does anyone have any ideas about what I’m doing wrong?

Many thanks!

  • Chris M.

6 Replies

Correction: The three directories I listed in my first post had typos in them – they're as follows on my site):

/var/www/bookgenius.org/html

/var/www/bookgenius.org/cgi-bin

/var/www/bookgenius.org/logs

  • Sorry!

Try disabling the default site:

a2dissite default

Also try to put your ip in the VirtualHost directive:

Disabling the default site did it! I'm getting my index.html page now.

Many thanks!

  • Chris M.

Just an addendum to anyone reading this thread who tries to create a similar setup. I thought I had solved the problem after setting up the first site, but when I added the second site, I got this warning message:

[warn] default VirtualHost overlap on port 80, the first has precedence

So, disabling the default web site wasn't enough. The solution (as karsh suggested in his post) was to change the VirtualHost directives in the two files in the sites-available directory to be the names of the two domains, e.g.:

But I also had to add the following NameVirtualHost line containing my specific IP address to the end of my apache2.conf file:

NameVirtualHost :80

This was because Apache wasn't happy with the virtual.conf file I had created that contained this line. (As I surfed the web looking for tips about setting up virtual servers, I found a lot of conflicting advice about where to put this NameVirtualHost line in the Apache2 file structure, but putting it at the end of apache2.conf worked for me.)

So, with all those changes made, I deleted the default file in the sites-available directory (so it wouldn't come back to haunt me). Then I ran a2dissite on both sites (just to clean things out), then I re-ran a2ensite on both sites, reloaded Apache, and both sites are now working correctly.

Yikes – this Virtual Hosting is tricky stuff! (Thanks again for the advice, karsh!)

  • Chris M.

@cpmorganesq:

I’m running Debian Etch.

Since your running Etch, this will give you a few starters for most things you may want to do.

http://www.linode.com/wiki/index.php/User:Kangaby

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