Tutorial
#2 - Apache Configuration - Running multiple sites
Description
To run multiple websites under Apache on a machine having single
IP either loopback 127.0.0.1 or other
Related
Tutorial
>> Installing Perl on Win9.x/Win 2000/Win
NT
>> Installing Apache on Win9.x/Win 2000/Win
NT [BASIC]
Prerequisites
>> Win NT/2000 - Admin Access
>> Complete path to various local website directories
>> Windows HOSTS file
Steps
Step1:
Download and Install latest stable Apache Win32 installable from
Apache.org
[P.S. Newer versions are available in only .MSI format]
Step2:
Test installation by running Apache server. Shutdown the server
once everything looks ok
Step3:
Next open the Apache configuration file HTTP.CONF
in Windows Notepad or any other text editor. This file is always
inside the directory CONF inside the Apache installation directory.
In this example under c:\apache\conf
Step4:
Now the to enable Virtual Hosts for Apache. Find the text "NameVirtualHost".
Generally near the end of the file.
Step5:
Change the entry from
#NameVirtualHost
*
to
NameVirtualHost 127.0.0.1:80
This
will configure the server to listen to port 80 on the IP 127.0.0.1
of the machine
Step6:
Next to define the individual virtual sites go to the <VirtualHost>
directive section, normally after "NameVirtualHost".
By default the entries would be similar to one below.
#<VirtualHost
*>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>
Change
the above to will enable the default Apache website installed under
C:\apache\htdocs\. This will
also log default site access and errors under the C:\apache\logs\
directory.
<VirtualHost
127.0.0.1>
ServerAdmin admin@localhost
DocumentRoot "c:/apache/htdocs"
ServerName localhost
ErrorLog logs/localhost_error.log
CustomLog logs/localhost_access.log common
</VirtualHost>
Step7:
Now to step-up multiple sites on the machine. Say the first site
name is "SITE1" add the following below the Virtual Host
directive for the default site [Step # 6]
<VirtualHost 127.0.0.1>
ServerAdmin webmaster@site1
DocumentRoot "c:/mywebsites/site1"
ServerName site1
ServerAlias *.site1
ErrorLog logs/site1-error.log
ScriptAlias /cgi-bin/ "c:/mywebsites/site1/cgi-bin/"
<Directory "c:/mywebsites/site1">
Options All Includes Indexes
</Directory>
</VirtualHost>
Document
Root points to the directory path where the SITE1 files are located.
IN the example above the files are located in C:\MYWEBSITES\SITE1
Server Name is the domain name of the site1 namely "SITE1"
ScriptAlias defines the cgi-bin directory for the site SITE1. This
will enable cgi scripts to run from the define directory
Repeat
this step for any number of sites required to run on the machine.
But take care to name each site differently
Step8:
Save and close the HTTP.CONF
Step9:
Now the most IMPORANT step, i.e. to define the DNS entries for each
of the sites created in step7. Open file "HOSTS"
in a text editor. This file is located in C:\WINDOWS
in Win9.x and C:\WINNT\SYSTEM32\DRIVERS\ETC
in Win NT/2000
Step10:
Add site names similar to this
127.0.0.1 site1
127.0.0.1 site2
127.0.0.1 site3
Take care not to leave
a blank carrige return in the end of the file. Save and exit
Step11:
Reboot the machine for changes to take effect
Step12:
Test the installation by pointing brower to http://localhost/
and http://site1/. The second URL will
show the index html file of SITE1
Additional
Tweak
In case the machine configured needs to serve sites to the local
network, the IP needs to be changed. In the example above the IP
used is a local loopback IP 127.0.0.1. If the machine is on a network
and has been assigned an IP say 192.168.0.10 replace all the 127.0.0.1
with 192.168.0.10. Also on each machine on the network the same
"HOSTS" file needs
to be copied for point to the machine running Apache Server.
|