Can't get virtual hosting working on Apache2
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:
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:
#
ServerAdmin
ServerName bookgenius.org
ServerAlias
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/
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
/var/www/bookgenius.org/html
/var/www/bookgenius.org/cgi-bin
/var/www/bookgenius.org/logs
- Sorry!
a2dissite default
Also try to put your ip in the VirtualHost directive:
Many thanks!
- Chris M.
[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.:
NameVirtualHost
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.