by Atif Ghaffar
About the author:
I live and work in Switzerland as a webmaster/unix administrator.
My passions include, Linux, unix, Perl, Apache and GPL softwares.
More about me can be found on my homepage
This article demonstrates how to serve multiple virtual webservers using the same ip address with Apache on Unix/Linux. The article assumes that the reader has some knowledge of Apache and DNS and unix.
The target audience of this article is ISPs, System Administrator and anyone who cares to read and learn.
Ip address recycling is useful for number of reasons.
#Host for unix files <VirtualHost 192.168.1.1:80> ServerName unix.hometranet.home DocumentRoot /www/unix/html ScriptAlias /cgi-bin/ /www/unix/cgi-bin/ TransferLog /www/unix/logs/access_log ErrorLog /www/unix/logs/error_log </VirtualHost> #Host for perl stuff <VirtualHost 192.168.1.1:80> ServerName perl.hometranet.home DocumentRoot /www/perl/html ScriptAlias /cgi-bin/ /www/perl/cgi-bin/ TransferLog /www/perl/logs/access_log ErrorLog /www/perl/logs/error_log </VirtualHost> #Here we host some cool Apache stuff <VirtualHost 192.168.1.1:80> ServerName apache.hometranet.home DocumentRoot /www/apache/html ScriptAlias /cgi-bin/ /www/apache/cgi-bin/ TransferLog /www/apache/logs/access_log ErrorLog /www/apache/logs/error_log </VirtualHost>So using one ip address we have easily managed 3 different virtualhosts.
This is the cool part. Apache allows wildcards to be used in hostanames.
Meaning you can set a domain *.home.hometranet.home and all queries to user1.home.hometranet.home, user2.home.hometranet.home, user3.home.hometranet.home,etc will be responded.
#host for users <VirtualHost 192.168.1.1:80> ServerName home.hometranet.home ServerAlias *.home.hometranet.home DocumentRoot /www/home/html TransferLog /www/home/logs/access_log ErrorLog /www/home/logs/error_log </VirtualHost> and an entry in the named zone file. *.home.hometranet.home. IN A 192.168.1.1Note: This trick will not work if you are using Microsoft DNS Server. Apparently it refuses to accept wildcards in hostnames.
Here is a bit more exhaustive configuration file that i have separated from my main httpd.conf file
This one is actually on my server.
To include this file in the main httpd.conf you can use the Include directive in your main httpd.conf.
Webpages maintained by the LinuxFocus Editor team
© Atif Ghaffar, FDL
Click here to report a fault or send a comment to LinuxFocus
2001-01-27, generated by lfparser version 2.8