Using Virtual Hosts

You can use Apache's virtual hosts capability to run different servers for different IP addresses, different host names, or different ports on the same server. If you are interested in using virtual hosts, complete information is provided in the Apache documentation on your machine or on the Web at


You cannot use name-based virtual hosts with your Red Hat Linux Advanced Server, because the SSL handshake occurs before the HTTP request which identifies the appropriate name-based virtual host. If you want to use name-based virtual hosts, they will only work with your non-secure Web server.

Virtual hosts are configured within the httpd.conf file, as described in the Section called Configuration Directives in httpd.conf. Please review that section before you start to change the virtual hosts configuration on your machine.

The Secure Web Server Virtual Host

The default configuration of your Web server runs a non-secure and a secure server. Both servers use the same IP address and host name, but they listen on different ports, and the secure server is a virtual host. This configuration enables you to serve both secure and non-secure documents in an manner. Setting up the secure HTTP transmission is very resource intensive, so generally you will be able to serve far fewer pages per second with a secure server. You need to consider this when you decide what information to include on the secure server and the non-secure server.

The configuration directives for your secure server are contained within virtual host tags in the httpd.conf file. If you need to change anything about the configuration of your secure server, you will need to change the configuration directives inside virtual host tags.

The non-secure Web server is configured as the "non-virtual" host in the httpd.conf file. If you want to change something about your non-secure Web server, you will need to change the configuration directives outside of the virtual host tags.

By default, both the secure and the non-secure Web servers share the same DocumentRoot. To change the DocumentRoot so that it is no longer shared by both the secure server and the non-secure server, change one of the DocumentRoot directives. The DocumentRoot outside the virtual host tags defines the DocumentRoot for your non-secure Web server. The DocumentRoot within the virtual host tags that define your secure server is for your secure server.

The secure Apache server listens on port 443, while your non-secure Web server listens on port 80. To stop the non-secure Web server from accepting connections find the line which reads:

Port 80

And change it to read:

Port 443

Then comment out the Listen 80 line.

Setting Up Virtual Hosts

To create a virtual host, you will need to alter the virtual host lines, provided as an example in httpd.conf or create your own virtual host section.

The virtual host example lines read as follows:

#    ServerAdmin
#    DocumentRoot /www/docs/
#    ServerName
#    ErrorLog logs/
#    CustomLog logs/ common

Uncomment all of the lines, and add the correct information for the virtual host.

In the first line, change to your server's IP address. Change the ServerName to a valid DNS name to use for the virtual host.

You will also need to uncomment one of the NameVirtualHost lines below:


Next change the IP address to the IP address and port, if necessary, for the virtual host.

If you set up a virtual host and want it to listen on a non-default port, you will need to set up a virtual host for that port and add a Listen directive for corresponding to that port.

Then add the port number to the first line of the virtual host configuration as in the following example:

<VirtualHost ip_address_of_your_server:12331>

This line would create a virtual host that listens on port 12331.

You must restart httpd to start a new virtual host. See the Section called Starting and Stopping httpd for instructions on how to start and stop httpd.

Comprehensive information about creating and configuring both name-based and IP address-based virtual hosts is provided on the Web at Please check the's virtual host documentation for more details on using virtual hosts.