Configuring

apache

for multiple virtual hosts

and multiple servers behind 1 IP address

USE AT YOUR OWN RISK

 
  Ok, you want to install multiple websites using a virtual host configuration or allow multiple servers to host behind one IP address. This applies to Linux/Apache and Windows/Apache configurations. I am assuming you know how to configure your domain name to point to your server. Follow these instructions for each domain name*.  
       
  Directories you should become familiar with: Files you will need to edit:  
  /etc httpd.conf  
  /etc/httpd/conf/ resolv.conf  
  /usr/local zone files  
  /var/www    
  /var/named    
       
  Services needed to run:    
  httpd    
  named    
       
  First you will need to set up your zone files for each domain:  
  Working directory = /var/named  
Start with this file (yourdoman.com)
This section does not apply to those using a Windows/Apache configuration 1) When creating a new zone file, you must remember to increment the serial number. (*Each zone file must have a unique Serial number.) 2) Now change all the relavent domain information.
3) Change the IP address to match your WAN IP address

Zone File

   
Editing the resolv.conf file:  
Working directory = /etc/resolv.conf  
This file should look like this:  
search yourdomain.com  
nameserver 0.0.0.0  
Where 0.0.0.0 is a valid DNS server IP  
       
  Now for the httpd.conf apache configuration file  
  Working directory = /etc/httpd/conf/httpd.conf (Will be different for Windows users) i.e. c:/apache/conf/httpd.conf  
  Start with this file (httpd.conf) ***Please back up your file first  
  1) At the end of the file is where you will need to make changes by changing the NameVirtualHost IP to the servers LAN IP. 2) Insert your domain and directory information into VirtualHost containers.  
 

Example:

 
  NameVirtualHost 192.168.0.4  
     
  <VirtualHost 192.168.0.4:80>  
         ServerAdmin webmaster@yourdomain.com  
         DocumentRoot /var/www/yourdomain  
         ServerName yourdomain.com  
         ServerAlias www.yourdomain.com  
  </VirtualHost>  
     

Follow the above instructions for each site you want to host

 

Multiple Servers behind 1 IP address

Forwarding requests to other servers in your network

<VirtualHost 192.168.0.4:80>
       ServerAdmin webmaster@yourdomain.com
       ServerName yourdomain.com
       ServerAlias www.yourdomain.com
      Redirect / http://www.yourdomain.com:81 where :81 is the port of another server
</VirtualHost>    
In the above configuration the port number will appear in the address bar and hyperlinks. To avoid this, do the following:
1) Uncomment (in two places) the proxy and rewrite modules in your http.conf file if they are not already (usually applies to Windows/Apache configurations)
2) Write the virtual hosts like below:
<VirtualHost 192.168.0.4:80>
       ServerAdmin webmaster@yourdomain.com
       ServerName yourdomain.com
       ServerAlias www.yourdomain.com
      Rewrite On
      RewriteRule ^/(.*) \http://www.yourdomain.com:81/$1 [P]
</VirtualHost>    
This will hide the :81 from the address, however, since it uses proxy you may run into some issues. For instance, I cannot access a frontpage site with this Rewrite rule, but I can get around it by just typing the :81 when I attempt to connect with FrontPage.

Also note, you will need to change the serving port of the server you are redirecting to. For example, if it is a web server it will more than likely be trying to listen on port 80 so you will need to configure such servers appropriately.

       
 

Restart named and httpd and you should be good to go (Restart apache for windows/apache configuration)

 
       
 

[ Powered by Apache ]      [Powered By Redhat]