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:http://httpd.apache.org/docs-2.0/vhosts/>

# 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/dummy-host.example.com

# ServerName dummy-host.example.com

# ErrorLog logs/dummy-host.example.com-error_log

# CustomLog logs/dummy-host.example.com-access_log common #</VirtualHost>

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

NameVirtualHost *

<VirtualHost *>

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

ErrorLog logs/handsonhistory.com-error_log CustomLog logs/handsonhistory.com-access_log common </VirtualHost>

<VirtualHost *>

DocumentRoot /var/www/linuxtoys ServerName www.linuxtoys.net ServerAdmin [email protected] ErrorLog logs/linuxtoys.net-error_log CustomLog logs/linuxtoys.net-access_log 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