Serving Virtual Hosts· 2 minute read
To begin with I am using Apache2 so this will not apply to Apache1.3. Apache2 uses an interesting technique for setting up Virtual Hosts, they are no longer stored in the huge httpd.conf file. They are stored in two folders, sites-available and sites-enabled.
I am basing this setup on the following structure:
/home/www/ -- www.sitename1.com -- htdocs -- stats -- logs -- www.sitename2.com -- htdocs -- stats -- logs
To make a new Virtual Host you make a new file in the sites-available directory. Sitename = your new site. Don’t forget to sudo if your not logged in as root
cd /etc/apache2/sites-available vi sitename
Then enter the following into your new file:
<VirtualHost *> ServerAdmin email@example.com ServerName sitename.com ServerAlias *.sitename.com DocumentRoot /var/www/sitename/htdocs ErrorLog /var/www/sitename/logs/error.log TransferLog /var/www/sitename/logs/access.log </VirtualHost>
The asterisk in the initial VirtualHost tag can be replaced by a particular IP address if your server has more than one.
You need to add a symlink to the sites-enabled directory for apache2 to add your new VirtualHost to its serving directories.
cd ../sites-enabled ln -s ../sites-available/sitename
Now you need to create the folders mentioned in the structure above:
mkdir /var/www/sitename mkdir /var/www/sitename/htdocs mkdir /var/www/sitename/htdocs/stats mkdir /var/www/sitename/logs /etc/init.d/apache2 restart
So you have your nice little virtual servers setup, but how do you know who is accessing them? Well the following article is good starting point: http://www.debian-administration.org/articles/85
However there are a few helpful extras that you need to know.
When installing and Debian asks you for the location of the log files you need to modify the path from /var/logs/apache/ to /var/logs/apache2 because you are running Apache2.
When creating that cron job in /etc/cron.daily you must set permissions for it:
chmod +x mycmds.sh
If you wish to run the script now to test it then you need to type:
Also when you run webalizer it may chuck an error saying something like it could not find /var/logs/apache2/access.log.1 This is because the log has not been rotated yet so if you don’t want to wait for the cron job to do it for you you can:
logrotate --force apache2