Published on: Monday 10th May 1999 By: Tarique Sani
When I put together our tiny (Server + 3 Clients) Linux based intranet I wanted a website on it. This was very simply achieved, but soon I suffered delusions of grandeur and imagined having departments like Lab, Public Relations, HRD each with their own independent websites on the company intranet. Sigh the dream continues but I did put up the websites like labs.SANIsoft.com and hrd.SANIsoft.com on the intranet. Here is how.
Apache is set up and ready to run automatically at boot as soon as the Linux installation is completed (of course if you chose install it). The current version of Apache is 1.3.3-x. It is available free with Red Hat Linux 5.2, you can also download it from http://www.apache.org. Apache webserver is extremely powerful, and can be configured to handle any kind of environment from a lightly loaded Intranet to a commercial Internet Web server taking more than 100,000 hits a day!
To check if Apache is working correctly, simply point your browser to the URL http://localhost. You should see Apache's default It Worked page start up. You can now simply change the index.html file in the /home/httpd/html directory on your own and start publishing pages on your Intranet. The default configuration file /etc/httpd/conf/httpd.conf is suitable for simple configurations, though you might want to edit it if you have an unusually heavy load, or wish to configure a different machine name, port, or address to send error messages.
There are two additional files in the conf directory. The access.conf file lets you define extra security parameters to your Web server, such as allowing only users from particular domains to browse. The srm.conf file allows you to tweak Apache's behaviour to handle newer MIME types, and set users home directories. You will not normally need to edit these files, but it is a good idea to check them out for any settings peculiar to your set up.
Multiple websites on your Intranet lie on a single Linux server, configured to use multiple interfaces with independent host names and IP addresses (also called Virtual Domains).
The first step is to set up multiple interfaces to your ethernet card. The existing interface will be eth0, hence use the ifconfig command to add a new interface to it: /sbin/ifconfig eth0:1 192.168.1.200. Now we have to add a route to the new interface: /sbin/route add -host 192.168.1.200 dev eth0:1 Make sure the 192.168.1.200 (or whatever you choose) is a reserved IP address and cannot by dynamically assigned by your DHCP server.
You can now ping the new IP address as any other address on the network. Now edit your nameserver files to give this interface a suitable name (say hrd.sanisoft.com). If you are running a DNS on you machine you can configure it from there (read Configuring DHCP And DNS Services).
Change to the directory /var/named. Edit the file named.xxx.yyy.forward (where xxx.yyy is your domain name). Replace ws200 with whatever you want to name your interface, in this case hrd Now restart named using the command /etc/rc.d/init.d/named restart. You should be able to Ping any interface by name from any machine on your network.
Last step is to create a file to add the interface and route automatically at boot time. Create a file (say rc.virtual) in the /etc/rc.d directory and add the above two lines to it. The file should read like this:
#!/bin/sh /sbin/ifconfig eth0:1 192.168.1.200 /sbin/route add -host 192.168.1.200 dev eth0:1
Mark it executable (chmod +x rc.virtual), then edit the file rc.local in the same directory. At the last line of that file, add the line /etc/rc.d/rc.virtual to run it automatically at boot.
What you have done is called IP Aliasing.
Once you have set up IP aliasing as described above, you have to configure Apache to work with the new domain.
The Apache configuration file allows you to configure virtual hosts to have their own document roots. At the bottom of the /etc/httpd/conf/httpd.conf file you will find a sample <VirtualHost domainname> tag. Add the Serveradmin address, and the servername to report (the virtual interface name, not the actual machine name). End the section with a </VirtualHost> tag see the example shown below:
<VirtualHost 192.168.1.200> ServerAdmin webmaster@SANIsoft.com DocumentRoot /groups/hrd/www ServerName hrd.SANIsoft.com ErrorLog /groups/hrd/logs/error_log TransferLog /groups/hrd/logs/access_log </VirtualHost>
Restart http using the command etc/rc.d/init.d/httpd restart. You can now browse the virtual domain name from any machine on your network.
The above method while having the advantage of working with older versions of Apache and older browsers as well, is none the less cumbersome as it requires a unique IP address for each of the virtual domains.
The other option is using the new name-based method for
setting up virtual hosts. The
contains a method for the server to identify what name it is
being addressed as. The benefits are - practically unlimited
number of servers, ease of configuration and use, and requires no
additional hardware or software.
Using the name based method is very simple you just add the NameVirtualHost directive to the /etc/httpd/conf/httpd.conf before the VirtualHost tag like shown below:
NameVirtualHost 188.8.131.52 <VirtualHost 184.108.40.206> ServerName hrd.SANIsoft.com DocumentRoot /web/where_ever_you_want_hrd_2b </VirtualHost>
To make this work, all that is needed is to make sure that the name hrd.SANIsoft.com points to the IP address 220.127.116.11. To do this you need to edit your DNS files exactly as described above. Additional directives should/can be placed in the virtual host tag. Restart the httpd and you will be able to access the new domian on your Intranet.
Start with the excellent documentation provided with the Apache itself, point your browser with a working apache server to http://localhost/manual.
You can read the book "Apache The Definitive Guide" by Ben Laurie and Peter Laurie, published by O'Reilly.
The same method can be used to set up multiple virtual domains on an Internet web server.