Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set up Name Based Vitualhosts on Apache.

VirtualHosts

How to set up Name Based Vitualhosts on Apache.

by  Wullie  Posted    (Edited  )
Code:
This explains how to use Namebased Virtualhosts on Apache 1.x. The following will also keep seperate logs for each Virtualhost, if you do not want this and you want all domains logs to be combined then remove the log entries in the virtualhost directives.

Uncomment    

BindAddress *

Also uncomment

NameVirtualHost *

Then at the bottom (This makes it easier to find in the future) of the httpd.conf, add the following lines.. The lines starting with a # are comments and can be removed.

<VirtualHost *:80>
   UseCanonicalName off
# Your domain name.
   ServerName domain.co.uk
# Any variation of your domain name.
   ServerAlias www.domain.co.uk
# Email address of server admin
   ServerAdmin webmaster@domain.co.uk
# Location of the sites files
   DocumentRoot /www/domain
# Location of your cgi-bin
   ScriptAlias /cgi-bin/ "C:/www/domain/cgi-bin/"
# Location of the sites log files
   ErrorLog logs/domain/error.log
   CustomLog logs/domain/access.log common
   CustomLog logs/domain/referer.log referer
   CustomLog logs/domain/agent.log agent
# Add email to server generated files
   ServerSignature EMail
</VirtualHost>

Just repeat this for each domain.

It will look something like the following:


<VirtualHost *:80>
   UseCanonicalName off
   ServerName domain.co.uk
   ServerAlias www.domain.co.uk
   ServerAdmin webmaster@domain.co.uk
   DocumentRoot /www/domain
   ScriptAlias /cgi-bin/ "C:/www/domain/cgi-bin/"
   ErrorLog logs/domain/error.log
   CustomLog logs/domain/access.log common
   CustomLog logs/domain/referer.log referer
   CustomLog logs/domain/agent.log agent
   ServerSignature EMail
</VirtualHost>
<VirtualHost *:80>
   UseCanonicalName off
   ServerName domain1.co.uk
   ServerAlias www.domain1.co.uk
   ServerAdmin webmaster@domain1.co.uk
   DocumentRoot /www/domain1
   ScriptAlias /cgi-bin/ "C:/www/domain1/cgi-bin/"
   ErrorLog logs/domain1/error.log
   CustomLog logs/domain1/access.log common
   CustomLog logs/domain1/referer.log referer
   CustomLog logs/domain1/agent.log agent
   ServerSignature EMail
</VirtualHost>


The first in the list is the default that is called if Apache doesn't recognise the server name.

If you decide to use seperate logs for each domain then to save yourself getting errors with the above added, make sure that the directories that are specified for the error logs exist..

Hope this helps

Wullie

sales@freshlookdesign.co.uk
www.freshlookdesign.co.uk
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top