NsVirtual module page

 

The NsVirtual module is a module, which is written for the needs of web hosting companies, who have to support lots of virtual hosts. We didn't have any time for testing it, but it seems to work fine. The whole idea came from the mod_vhost_alias module in Apache, which makes a url2file mapping for each virtual host. We extended the idea here and decided to use the ability of AOLserver to communicate with databases (MySQL in our case). What this module does is a very simple url2file mapping. It uses a table in the database, which has two columns - in the first column we store the virtual hosts (foo.bar.com for example) and in the second column we store the DocumentRoot directory for this virtual host (/home/httpd/html/foo-bar). When the module is initialized it reads this table and stores the two values for each virtual host in a Ns_Set, where the first column is the key and the second column is the value. When a url i requested we read the Host header, passed to the web server and get the DocumentRoot path in the Ns_Set. We've also added a scheduled procedure, which executes on every 5 minutes and appends the virtual hosts that are new for our Ns_Set. We decided to make it such way in order the module to be faster and with less code. We met a problem with the trailing slashes with this module - if somebody requests http://foo.bar.com (not http://foo.bar.com/) the AOLserver redirects internally this request to the hostname of the server, which in our case is not the redirect that we should have. That's why we made a tiny patch of the return.c file, which is part of the AOLserver. Here are the patch, the module and the "vhost" table dump:

For any comments, bug fixes and patches e-mail us at: maav@bastun.net and maniax@phreedom.org