I have a Linux server with Apache and virtual hosting installed and like to keep things as simple as possible.
I'm using the normal directory structure as the database for all the virtual hosts.
Creating a new virtual host is as simple as creating a directory in the right place.
I have it working on my Fedora Core machine with Apache, but also wanted to have it on my WDMB.
Every week a cronjob is pulling my complete vhost folder from my Linux machine to the worldbook and I thought it was a good idea to be able to use it in the same way.
For now I'm running vhosting on port 8080, but that's more an enhancement.
It's even easier to let it run everything on port 80
ok… let's start
I don't like to change configs that are already there, so I'm keeping that to the minimum.
I will create a special directory for the new configs…
mkdir /etc/lighttpd/conf.d
Add a line to /etc/lighttpd/lighttpd.conf, but first backup your conf
cp -p /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.`date +%F`
echo -e "include_shell \"cat /etc/lighttpd/conf.d/*.conf\"" >> /etc/lighttpd/lighttpd.conf
vi /etc/lighttpd/conf.d/evhost.conf
Create the file /etc/lighttpd/conf.d/evhost.conf with the following content
server.modules += ( "mod_evhost" )
$SERVER["socket"] == ":8080" {
server.document-root = "/shares/internal/WWW/vhosts/oops/"
evhost.path-pattern = "/shares/internal/WWW/vhosts/%1/%2/%3/"
}
mkdir -p /shares/internal/WWW/vhosts
chown -R www-data:www-data /shares/internal/WWW
/etc/init.d/lighttpd.sh restart
Your directory structure can look like this:
/shares/internal/WWW/vhosts/oops
/shares/internal/WWW/vhosts/com/wikidot/myworldbook
/shares/internal/WWW/vhosts/com/wikidot/www
/shares/internal/WWW/vhosts/com/wikidot/hacking
/shares/internal/WWW/vhosts/com/mybook/www
/shares/internal/WWW/vhosts/net/martinhinner/www
/shares/internal/WWW/vhosts/org/hacking/www
That's it really….
After understanding the concept you can "upgrade" the setup by running the non-vhost on port 8080 and make the vhosting on port 80.
Your normal admin-page is still on port 80. If everything works as you want it, you can easily swap the ports (vhosting on port 80 and IP-based on port 8080)
I already did that on my config.
When you type a wrong url you can direct it to an "oops" page.
To standard webinterface can be easily added to the vhost directory structure using a symbolic link.
My local DNS points mybook.mydomain.com to the IP of the WDMB, so I created this symbolic link
ln -s /usr/www/lib/ /shares/internal/WWW/vhosts/com/mydomain/mybook
When I type mybook.mydomain.com, it will go to the normal admin page. On port 8080 it will always go to the admin page (if you did the swap)
BTW… A nice trick to test virtual hosting on a specific server is configuring your webbrowser to use a proxy (extra => options) and give it the IP and portnumber of the server you are testing. Much easier and better than a hostfile which you might forget to revert to normal. It is this way also impossible to browse normally (I always use Internet Exploder for this and have Firefox do the normal browsing)