Configuring virtual hosting

If you have one Web server computer, but more than one domain that you want to serve with that computer, you can set up Apache to do virtual hosting. With virtual hosting, a single IP address can be the access point for multiple domain names.

With virtual hosting, when a request comes into your Apache server from a Web browser through a particular IP address on your computer, Apache checks the domain name being requested and displays the content associated with that domain name. As an administrator of a Web server that supports virtual hosting, you must make sure that everything that needs to be configured for that virtual server is set up properly (you must define such things as locations for the Web content, log files, administrative contact, and so on).

Virtual hosting is defined with the VirtualHost tags. Information related to virtual hosts in the /etc/httpd/conf/httpd.conf file is shown in the following code:

# VirtualHost: If you want to maintain multiple domains/hostnames on

# your machine you can setup VirtualHost containers for them. Most

# configurations use only name-based virtual hosts so the server

# doesn't need to worry about IP addresses. This is indicated by the

# asterisks in the directives below.

# Please see the documentation at

# <URL:>

# for further details before you try to setup virtual hosts.

# You may use the command line option '-S' to verify your virtual host

# configuration.

# Use name-based virtual hosting.

#NameVirtualHost * #

# VirtualHost example:

# Almost any Apache directive may go into a VirtualHost container.

# The first VirtualHost section is used for requests without a known

# server name.

# ServerAdmin [email protected]

# DocumentRoot /www/docs/

# ServerName

# ErrorLog logs/

# CustomLog logs/ common #</VirtualHost>

The following is an example of virtual host directives that would allow you to host the domains and on the same computer:

NameVirtualHost *

<VirtualHost *>

DocumentRoot /var/www/handsonhistory ServerName ServerAdmin [email protected]

ErrorLog logs/ CustomLog logs/ common </VirtualHost>

<VirtualHost *>

DocumentRoot /var/www/linuxtoys ServerName ServerAdmin [email protected] ErrorLog logs/ CustomLog logs/ common </VirtualHost>

Was this article helpful?

0 0
Digital Photography Mastery

Digital Photography Mastery

Insider Secrets Revealed By the Pro Showing You How to Become a Professional Photographer! Discover The Secret Tips & Techniques On How To Be A Professional Photographer, Start Producing High Quality Pictures and Skyrocket Your Photography Business Income Revenue To The Roof TODAY! You're About to Discover the Powerful Strategies and Method to Start Taking Sharp, Clear and High Quality Pictures Like the Professional Photographer Without Paying a Single Penny to the Expert!

Get My Free Ebook

Post a comment