- Linux Training
- Desktop Tutorials
- Server Tutorials
|Apache: Name Based Hosting|
|Server Training - Web Server|
There are basically two possibilities for Virtual Hosting. One is Name Based Hosting which uses one IP Address for all of the domains that are on the server. Once a domain name is registered and setup the web server will serve the correct domain name despite being on the same IP Address. IP based hosting requires a separate IP Address for each server. This tutorial will help you set up the Name Based Hosting on an Apache Web Server.
If you want to learn about Ubuntu Name Based Hosting CLICK HERE. The reason is that Ubuntu and CentOS are configured differently. The documentation on this page is for centOS.
In order to use Name Based Hosting you will need to use the NameVirtualHost directive and supply the IP Address, this must be a public IP Address for the Internet. The VirtualHost directives enclose each virtual host:
Used to enclose a group of directives that will impact only one virtual host.
Each Virtual Host must correspond to a different IP address, different port number or a different host
Live Class Descriptions:
Here is an example of several named based setups.
NameVirtualHost 192.168.5.56 ###note this is a private IP Address in the example
There are several parts to note with Named Based setups. DocumentRoot is the location on the server where the main documents or web pages for the domain must be placed. The example shows:
This DocumentRoot directory must be declared in this directive. It could be other places on the server, for example:
The important thing to do is create a pattern so you can place these directories in a partition or directory that can be backed up and it is easier to configure.
When the server is created you must know where you will locate the web services. If the /var directory will be used it must be large enough to hold all of the web services as well as a large number of growing logs. If the /usr/local directory will be used it too must have the resources to grow to the organization’s needs.
The ServerName is also important to declare in the directive. The domain name for the specific server must be declared. This declaration may be with the www included or not.
The ErrorLog determines where the errors for a specific domain will be located. It is most valuable to have logs in the same directory as the domain. Place the logs directory at the same level as the html directory. Here is an example:
Typically, logs are placed in /var/log/httpd unless you have a number of virtual hosts which you may want the logs to be separate then. It is often safer to not place the logs directory in the same directory as the html pages that users will view. This mainly reminds you that the logs directory should not be read by any user except apache.
The actual http.conf or apache2.conf if you are using Ubuntu 8.04 section for Virtual Hosts is listed below.
### Section 3: Virtual Hosts
# 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
# for further details before you try to setup virtual hosts.
# You may use the command line option '-S' to verify your virtual host
# Use name-based virtual hosting.
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
# 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.
# 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
Copyright CyberMontana Inc. and BeginLinux.com
All rights reserved. Cannot be reproduced without written permission. Box 1262 Trout Creek, MT 59874