Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


boostr.in questions - Question:how to setup Virtual Hosts?


 

Virtual Hosts:

The Apache web server allows one to configure a single computer to represent multiple websites as if they were on separate hosts. There are two methods available and we describe the configuration of each. Choose one method for your domain:

  • Name based virtual host: (most common) A single computer with a single IP adress supporting multiple web domains. The web browser using the http protocol, identifies the domain being addressed.
  • IP based virtual host: The virtual hosts can be configured as a single multi-homed computer with multiple IP addresses on a single network card, with each IP address representing a different web domain. This has the appearance of a web domain supported by a dedicated computer because it has a dedicated IP address.

 

Configuring a "name based" virtual host:

A virtual host configuration allows one to host multiple web site domains on one server. (This is not required for a dedicated linux server which hosts a single web site.)

 

NameVirtualHost XXX.XXX.XXX.XXX

XXX.XXX.XXX.XXX>
   ServerName www.your-domain.com          - CNAME (bind DNS alias www) specified in Bind configuration file (/var/named/...)
   ServerAlias your-domain.com             - Allows requests by domain name without the "www" prefix.
   ServerAdmin user1@your-domain.com
   DocumentRoot /home/user1/public_html
   ErrorLog logs/your-domain.com-error_log
   TransferLog logs/your-domain.com-access_log

Notes:

  • You can specify more than one IP address. i.e. if web server is also being used as a firewall/gateway and you have an external internet IP address as well as a local network IP address.
    NameVirtualHost XXX.XXX.XXX.XXX
    NameVirtualHost 192.168.XXX.XXX
    
    XXX.XXX.XXX.XXX 192.168.XXX.XXX>
       ...
       ..
    
  • Use your IP address for XXX.XXX.XXX.XXX, actual domain name and e-mail address.
    One can use DNS views to provide different local network DNS results.

     

  • Note that I configure Apache for both requests http://www.domain-name.com and http://domain-name.com.

     

  • Once virtual hosts are configured, your default system domain (/var/www/html) will stop working. Your default domain now must be configured as a virtual domain.
    
    
       ...  This part remains the same
       ..
    
    
    
    # Default for when no domain name is given (i.e. access by IP address)
    
    *:80>
       ServerAdmin user1@your-domain.com
       DocumentRoot /var/www/html
       ErrorLog logs/error_log
       TransferLog logs/access_log
    
    
    # Add a VirtualHost definition for your domain which was once the system default.
    
    XXX.XXX.XXX.XXX>
       ServerName www.your-domain.com
       ServerAlias your-domain.com
       ServerAdmin user1@your-domain.com
       DocumentRoot /var/www/html
       ErrorLog logs/error_log
       TransferLog logs/access_log
    
    
       ...
       ..
        

     

  • Forwarding to a primary URL. It is best to avoid the appearance of duplicated web content from two URLs such as http://www.your-domain.com and http://your-domain.com. Supply a forwarding Apache "Redirect".
    XXX.XXX.XXX.XXX>
       ServerName www.your-domain.com   - Note that no aliases are listed
       ...
       ...
    
    
    # Add a VirtualHost definition to forward to your primary URL
    
    XXX.XXX.XXX.XXX>
       ServerName your-domain.com
       ServerAlias other-domain.com
       ServerAlias www.other-domain.com
       Redirect permanent / http://www.your-domain.com.com/
    
    
       ...
       ..
        
    Note:      

asked Sep 13, 2013 in LINUX by anonymous
edited Sep 12, 2013
0 votes
15 views



Related Hot Questions



Government Jobs Opening


...