Web Hosting How-Tos

  Home arrow Web Hosting How-Tos arrow Configuring Apache – Intermediate
Web Hosting Articles  
Web Hosting FAQs  
Web Hosting How-Tos  
Web Hosting News  
Web Hosting Reviews  
Web Hosting Security  
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WEB HOSTING HOW-TOS

Configuring Apache – Intermediate
By: Michael Swanson
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 23
    2005-01-12

    Table of Contents:
  • Configuring Apache – Intermediate
  • Modules
  • Authentication
  • Authorization

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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
     
     

    SEARCH WEB HOSTERS

    TOOLS YOU CAN USE

    advertisement

    Configuring Apache – Intermediate


    (Page 1 of 4 )

    As a Web host, some key issues you will need to deal with when setting up a Web server include serving multiple domains on a single server, authorization, and authentication. In this second article on configuring Apache, Michael Swanson explains how to perform these tasks.

    In the previous article in this series, we described how to set up a basic Apache Web server for simple, static HTML page hosting, and also explained how to create the virtual directory structure that Apache uses to serve files out on the Web. This article will address some of the more complex issues involved with configuring an Apache Web server. Specifically, we will address how to use virtual hosts to serve multiple domains on a single physical server, how to add modular functionality to handle specific types of files (server side pre-processing of files for things like PHP and Python), and how to use authentication and authorization schemes to control access to different parts of your website.

    Virtual Hosts

    Often it is useful to be able to host more than one domain on a single server running a single instance of Apache. There are several possible ways to accomplish this without using the Virtual Hosts technique I will describe here.  However, they involve fairly kludgey solutions, such as running multiple instances of Apache on a single machine with each listening to a different port, and then using DNS redirects to forward requests for each domain to the correct port. Apache has a much more elegant solution for this problem.

    That solution is Virtual Hosts. These allow Apache to host a different site depending on several different criteria. First, if you have the luxury of multiple static IP addresses for a single machine, you can bind different Virtual Hosts to those separate IP addresses and define different “DocumentRoot” tags for requests coming in on different IP addresses. This is called IP-base Virtual Hosting. 

    The other option is called Name-based Virtual Hosting. This type of Virtual Hosting takes advantage of a header field set by most modern browsers that sends the name of the site the browser is requesting along with its actual request for content. This allows you to serve multiple different domain names on a single IP address. While most browsers support this type of HTTP request and do set this header field, it is important to note that if the “Name” header field is not sent along with the HTTP request coming from the browser, Name-based Virtual Hosting will not work correctly and the user will be served the default website. However, every modern browser in any sort of widespread use supports this feature, so you really only need to worry about this if for some reason supporting very old browsers is a specific need for you.

    This feature is configured in the httpd.conf file by adding another sub-block to the configuration. To set up virtual hosting, you use the <VirtualHost> and </VirtualHost> tags to delineate the configuration of each virtual host. If you plan to use IP based virtual hosting, you must make sure that the “Listen” directive directs the server to listen to all of the IP addresses and ports to which you wish to serve files. To configure an IP based Virtual Host to listen to 123.234.111.222:80 you would use a Virtual Host container like the following:


     Listen 123.234.111.222:80
    . …
    <VirtualHost 123.234.111.222:80>
      ServerName myserver.mydomain.com
      DocumentRoot /www/myserver/
     </VirtualHost>

    This creates a virtual host that listens to 123.234.111.222 on port 80 and serves the folder /www/myserver/ as the root of the myserver.mydomain.com domain. You can easily define multiple different blocks of these configurations to handle many domains. To use name based hosting, you will need to invoke the “NameVirtualHost” directive on the IP address for which you will be using Name-based Virtual Hosts. This is done with the following code:

     Listen 123.234.111.222:80
     …
     NameVirtualHost 123.234.111.222
     <VirtualHost 123.234.111.222:80>
      ServerName myserver1.mydomain.com
      DocumentRoot /www/myserver1
     </VirtualHost>

     <VirtualHost 123.234.111.222:80>
      ServerName myserver2.mydomain.com
      DocumentRoot /www/myserver2
     </VirtualHost>

    The above configuration will define two different hosts to be served on the 123.234.111.222 IP address. The “ServerName” directive in each “VirtualHost” block determines what files will be served based on the “Name” HTTP headers sent by the browser. This capability is very useful for small home-based Web serving environments where obtaining multiple actual WAN IP addresses would be difficult or impossible. 

    More Web Hosting How-Tos Articles
    More By Michael Swanson

    WEB HOSTING HOW-TOS ARTICLES

    - Phishing Scams: An Overview and How to Detec...
    - Tips for Safe Downloading Online
    - How To Avoid Spam
    - How to Get Into Ethical Hacking
    - How to Prevent Drive-by Downloads
    - Facebook Timeline Tips and Tricks
    - How to Keep Up with Facebook`s Changes
    - Wi-Fi Network Security Tips
    - Tips for Safe Online Holiday Shopping
    - Facebook Privacy: Keeping Up with the Const...
    - Tips for Facebook Privacy
    - How to Cover Your Tracks on the Web
    - SSH Keys for FileZilla and Putty in Cpanel
    - How to Create a Filezilla FTP User
    - How to Install FileZilla Server

    Developer Shed Affiliates

     




    © 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap