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 
  >>> SIGN UP!  
  Lost Password? 

Configuring Apache – Intermediate
By: Michael Swanson
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 24

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

  • Rate this Article: Poor Best 
      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




    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 you would use a Virtual Host container like the following:

    . …
      ServerName myserver.mydomain.com
      DocumentRoot /www/myserver/

    This creates a virtual host that listens to 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:

      ServerName myserver1.mydomain.com
      DocumentRoot /www/myserver1

      ServerName myserver2.mydomain.com
      DocumentRoot /www/myserver2

    The above configuration will define two different hosts to be served on the 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


    - 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-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap