Home arrow Site Administration arrow Page 2 - Getting More Out Of Apache (Part 1)

Virtually Yours - Administration

While the default Apache configuration is good enough for mostWeb applications, there's a lot more under the hood of the planet's mostpopular Web server. In this article, find out how to create virtual hostson a single Web server, and use Server-Side Includes for greaterflexibility in your HTML pages.

  1. Getting More Out Of Apache (Part 1)
  2. Virtually Yours
  3. Two Birds With One Host
  4. Gotcha!
  5. Including A Few More Tricks
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 6
January 04, 2001

print this article


It's a common misconception that a single Web server can host, or "serve", only a single Web site, since a server typically has only a single IP address assigned to it. This is not at all true - and over the next couple of pages, I'll be showing you how you can use Apache to serve up more than one Web site at a time.

First, though, the basics - every computer on the Internet is assigned an IP address, which serves as a unique identifier for that computer. In order to connect to a Web site, a user needs to know the IP address of the computer on which that Web site is stored. However, since users cannot be expected to remember strings of numbers for different Web sites, the Domain Name System was introduced to make things a little easier.

The Domain Name System, or DNS, maps each numeric string to an easy-to-remember word or phrase. For example, the IP address and the word "yahoo.com" both refer to the same Web site; however, the latter is much easier to remember. By mapping names to IP addresses, the DNS makes it easier to navigate the Web.

What does this have to do with Apache? Well, Apache was the first Web server to introduce "name-based virtual hosting". The concept is simple and elegant: different domain names all point to the same IP address, and the Web server at that IP address has the intelligence necessary to display a different Web page for each domain.

Name-based virtual hosting has been available since the HTTP/1.1 protocol came out. However, there is one gotcha - in order for this to work, the client browser must also include support for HTTP/1.1. Most newer browsers do include this support - and for those which don't, there's a workaround which allows them to perceive similar functionality.{mospagebreak title=Alpha And Beta} The keys to name-based virtual hosting are the appropriately-named NameVirtualHost and directives in the "httpd.conf" configuration file; these directives are used to specify basic information for the "virtual host", such as server name and server root, administrator email address, and log file locations.

Let's consider a simple scenario - creating two virtual hosts on the domain "localhost" (your Linux box) for the Web sites "melonfire-alpha.com" and "melonfire-beta.com". With the new NameVirtualHost directive, this is simplicity itself - open up the "httpd.conf" file in your favourite text editor, look for the "Virtual Hosts" section, and add the following entry to it:

The NameVirtualHost directive specifies the IP address of the server which will be used to resolve virtual host names.

With that out of the way, it's now time to begin adding the virtual host definitions themselves.

<VirtualHost> ServerAdmin webmaster@melonfire-alpha.com DocumentRoot /www/melonfire-alpha.com ServerName melonfire-alpha.com ErrorLog logs/melonfire-alpha.com-error_log CustomLog logs/melonfire-alpha.com-access_log common </VirtualHost>
Let's dissect this a little.

The first line

specifies the IP address of the virtual host. Very simply, this is the IP address of the machine that holds the Web pages you plan to display. In the example above, the machine is "localhost", which traditionally has the IP address

The second line

ServerAdmin webmaster@melonfire-alpha.com
specifies the email address of the administrator for this virtual host.

The third and fourth lines

DocumentRoot /www/melonfire-alpha.com ServerName melonfire-alpha.com
are probably the most important - they specify the domain name for the virtual host, and the physical location of the Web pages for that domain on the hard drive. Both these lines are crucial to ensuring that the correct Web page appears when the domain is accessed by a client browser.

Finally, the remaining two lines

ErrorLog logs/melonfire-alpha.com-error_log CustomLog logs/melonfire-alpha.com-access_log common
specify the files to which server activity is to be logged. You can log server visits and server errors to separate files for each of your virtual hosts, or put it all into the common log files (the default option).

You can also add other Apache directives to this virtual host entry. Once you're done, close the entry with a


>>> More Site Administration Articles          >>> More By icarus, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Coding: Not Just for Developers
- To Support or Not Support IE?
- Administration: Networking OSX and Win 7
- DotNetNuke Gets Social
- Integrating MailChimp with Joomla: Creating ...
- Integrating MailChimp with Joomla: List Mana...
- Integrating MailChimp with Joomla: Building ...
- Integrating MailChimp with Joomla
- More Top WordPress Plugins for Social Media
- Optimizing Security: SSH Public Key Authenti...
- Patches and Rejects in Software Configuratio...
- Configuring a CVS Server
- Managing Code and Teams for Cross-Platform S...
- Software Configuration Management
- Back Up a Joomla Site with Akeeba Backup

Developer Shed Affiliates


Dev Shed Tutorial Topics: