Apache – Virtual Hosts Configuration

Apache – Virtual Hosts Configuration

VirtualHost
and tags create a container outlining the characteristics of a virtual host. The container accepts most configuration directives.
A set of commented VirtualHost container is provided in httpd.conf, which illustrates the minimum set of configuration directives necessary for each virtual host.

Setting Up Virtual Hosts
To create a name-based virtual host, it is best use the virtual host container provided in httpd.conf as an example.
The virtual host example read as follows:

#NameVirtualHost *
#
#
# 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
#

To activate name-based virtual hosting, uncomment the NameVirtualHost line by removing the hash mark (#) and replace the asterisk (*) with the IP address assigned to the machine.

Next, configure a virtual host, by uncommenting and customizing the container.

On the line, change the asterisk (*) to the server’s IP address. Change the ServerName to a valid DNS name assigned to the machine, and configure the other directives as necessary.

The container is highly customizable and accepts almost every directive available within the main server configuration.

Tip
If configuring a virtual host to listen on a non-default port, that port must be added to the Listen directive in the global settings section of the /etc/httpd/conf/httpd.conf file.

To activate a newly created virtual host the Apache HTTP Server must be reloaded or restarted.

The Secure Web Server Virtual Host
By default, the Apache HTTP Server is configured as both a non-secure and a secure server. Both the non-secure and secure servers use the same IP address and host name, but listen on different ports: 80 and 443 respectively. This enables both non-secure and secure communications to take place simultaneously.
One aspect of SSL enhanced HTTP transmissions are that they are more resource intensive than the standard HTTP protocol, so a secure server cannot serve as many pages per second. For this reason it is often a good idea to minimize the information available from the secure server, especially on a high traffic Web site.
The configuration directives for the secure server are contained within virtual host tags in the /etc/httpd/conf.d/ssl.conf file.

By default, both the secure and the non-secure Web servers share the same DocumentRoot. It is recommended that the DocumentRoot be different for the Secure Web servers.

To stop the non-secure Web server from accepting connection comment the line in httpd.conf which reads Listen 80 by placing a hash mark at the beginning of the line. When finished it will look like the following example:
#Listen 80

Default Modules
The Apache HTTP Server is distributed with a number of modules. By default the following modules are installed and enabled with the httpd package on Red Hat Linux:

mod_accessDedicated Hosting
mod_auth
mod_auth_anon
mod_auth_dbm
mod_auth_digest
mod_include
mod_log_config
mod_env
mod_mime_magic
mod_cern_meta
mod_expires
mod_headers
mod_usertrack
mod_unique_id
mod_setenvif
mod_mime
mod_dav
mod_status
mod_autoindex
mod_asis
mod_info
mod_cgi
mod_dav_fs
mod_vhost_alias
mod_negotiation
mod_dir
mod_imap
mod_actions
mod_speling
mod_userdir
mod_alias
mod_rewrite
mod_proxy
mod_proxy_ftp
mod_proxy_http
mod_proxy_connect

Additionally, the following modules are available by installing additional packages:

mod_auth_mysql
mod_auth_pgsql
mod_perl
mod_python
mod_ssl
php
squirrelmail

Adding Modules
The Apache HTTP Server supports Dynamically Shared Objects (DSOs) or modules, which can easily be loaded at runtime as necessary.
For the Apache HTTP Server to use a DSO, it must be specified in a LoadModule directive within in /etc/httpd/conf/httpd.conf; if the module is provided by a separate package, the line must appear within the modules configuration file in the /etc/httpd/conf.d/ directory.If adding or deleting modules from http.conf, Apache HTTP Server must be reloaded or restarted.
If creating a new module, first install the httpd-devel package as it contains the include files, the header files, as well as the APache eXtenSion (/usr/sbin/apxs) application, which uses the include files and the header files to compile DSOs.
After writing a module, use /usr/sbin/apxs to compile the module sources outside the Apache source tree. Once compiled, put the module in the /usr/lib/httpd/ directory. Then add a LoadModule line to the httpd.conf, using the following structure:
LoadModule

In the above example, change to the name of the module and
to the path to the DSO.

Related Articles on Apache :-
Apache Main Server Configuration
Features of Apache HTTP Server 2.0
Apache Global Environment Configuration
Apache Virtual Hosts Configuration
Securing Apache / http server
Apache Installation

Like this post ?

Share on your Social Networking Profile ( Facebook, Twitter & Google+ ) and get a flat 10% Recurring discount on our VPS Hosting and Dedicated Servers.

Email us the shared link at : [email protected] or speak to our live chat operator now, by clicking on the “Live Chat” Scroller on the left-hand side of this page and we will provide you with the discount Coupon right away!

Latest posts by Sam (see all)

Sharing

Leave your comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.