Apache
  Home arrow Apache arrow Page 3 - Configuring and Using Virtual Hosts in Apache
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
APACHE

Configuring and Using Virtual Hosts in Apache
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 101
    2004-06-30


    Table of Contents:
  • Configuring and Using Virtual Hosts in Apache
  • Edit the Main Configuration File
  • Virtual Host
  • Find File System Called Hosts

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Configuring and Using Virtual Hosts in Apache - Virtual Host
    ( Page 3 of 4 )

    To begin, remove the comment symbol from the start of the NameVirtualHost directive.  By default this should already be followed by *:80, this means the server will listen to any and all IP addresses on port 80 (the default port for web services). 

    Next you can either add the directive <VirtualHost www.site1.co.uk> to the very bottom of the file, or remove the hash symbol and overtype the example. Remember, this needs to match the server name defined in section 2 of the configuration file.

    Next, explicitly state the server name:

    ServerName www.site1.co.uk 

    The next line of code defines the folder that normal HTML documents are served from; add DocumentRoot "pathtoyourdocumentroot" to the next line.  The document path will typically be something like www/var/html/site1 on a UNIX platform.

    Lastly, add ServerAdmin webmaster@site1.co.uk to give a contact email address on error documents and add the closing </VirtualHost> tag.

    Now, you need to define the actual virtual host; copy the block of text that you have just created and paste it directly below it. Now just change the values containing site1 to site2 and ensure the document root statement matches your directory set up. Now save the file and restart Apache to update its configuration.

    Simply using the technique described above will not let web users access your virtual site; in order for them to use the site URL, it will need to be included on the servers DNS record. This is relatively easy and usually requires you to simply add the virtual host name to the existing line of the DNS record for your IP address. When using IP based virtual hosts, you will need to add the IP address and the virtual server name below your existing IP address and host name.

    Configuring IP based virtual hosts is usually similar although you use the IP address for your virtual host in the opening <VirtualHost> tag, for example;

    <VirtualHost 123.45.6.78>  

    Next state the site name in the ServerName directive, e.g.

    ServerName www.site2.co.uk

    You then add the remaining ServerAdmin etc, directives. In addition to this, in order to make Apache bind to the appropriate IP addresses and server names, you will need to add a listen directive to section 1 of the httpd.conf file. There should already be one present, so scroll up through the file until you find it and add Listen 123.45.6.78:80 (or whatever happens to be the IP address you have been allocated.)  Once you have saved the configuration file and restarted the server, and the DNS records have been updated, this should then work.

    When setting up IP based virtual hosts, you will need to have already acquired your IP addresses. These can be obtained normally from your ISP.



     
     
    >>> More Apache Articles          >>> More By Dan Wellman
     

       

    APACHE ARTICLES

    - Creating a VAMP (Vista, Apache, MySQL, PHP) ...
    - Putting Apache in Jail
    - Containing Intrusions in Apache
    - Server Limits for Apache Security
    - Setting Permissions in Apache
    - Installing Apache
    - Apache Installation and Configuration
    - Apache Tapestry and Custom Components: DateI...
    - Tapestry and AJAX: Autocompleter and InlineE...
    - PropertySelection and IPropertySelectionMode...
    - The DatePicker and Shell Components of Apach...
    - Apache Tapestry: ASO and More Components
    - Apache Tapestry and DirectLink, IoC and DI
    - Making a CelebrityCollector with Apache Tape...
    - Apache Tapestry and Listener Methods, Condit...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT