Configuring Virtual Hosts in Apache


The configuration detailed here represents the Apache virtual host configuration which gives the web server administrator the greatest flexibility and freedom for specifying virtual hosts based on both name and port number. Obviously not all configuration directive have been included; I didn’t want to confuse the issue by including a full httpd.conf/httpsd.conf file — only the directive which must or should be specified when configuring virtual hosts.

My second disclaimer is that httpd.conf files are like anything else in the sysadmin world– everyone has their own individual preferences. My configurations are based on the following principles:

  • Every user’s web path resides in their home directory tree
  • Each user’s logs reside in a log directory in the user’s home directory tree
  • The cgi-bin directory is script aliased to prevent improper web access to the CGI files
  • The images directory is aliased for ease of access and to prevent web visitors from scanning through indexes of image files
  • CGI has been specifically allowed outside the user’s cgi-bin directory, but can be just as easily disabled (by removing ExecCGI from the access Options).



NameVirtualHost 172.16.17.92:80
NameVirtualHost 172.16.17.92:8080

# Configuration for http://joe.domain.com #
ServerName joe.domain.com
ServerAdmin webmaster@joe.domain.com
DocumentRoot /usr/home/joe/www/
ScriptAlias /cgi-bin/ /usr/home/joe/cgi-bin/
Alias /images/ /usr/home/joe/images/
ErrorLog /usr/home/joe/log/error_log-joe.domain.com
CustomLog /usr/home/joe/log/access_log-joe.domain.com common

Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all

# Configuration for http://joe.domain.com:8080 #
ServerName joe.domain.com
ServerAdmin webmaster@joe.domain.com
DocumentRoot /usr/home/joe/www8080/
ScriptAlias /cgi-bin/ /usr/home/joe/cgi-bin/
Alias /images/ /usr/home/joe/images/
ErrorLog /usr/home/joe/log/error_log-joe.domain.com8080
CustomLog /usr/home/joe/log/access_log-joe.domain.com8080 common

Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all

# Configuration for http://sally.domain.com #
ServerName sally.domain.com
ServerAdmin webmaster@sally.domain.com
DocumentRoot /usr/home/sally/www/
ScriptAlias /cgi-bin/ /usr/home/sally/cgi-bin/
Alias /images/ /usr/home/sally/images/
ErrorLog /usr/home/sally/log/error_log-sally.domain.com
CustomLog /usr/home/sally/log/access_log-sally.domain.com common

Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all

# Configuration for http://sally.domain.com:8080 #
ServerName sally.domain.com
ServerAdmin webmaster@sally.domain.com
DocumentRoot /usr/home/sally/www8080/
ScriptAlias /cgi-bin/ /usr/home/sally/cgi-bin/
Alias /images/ /usr/home/sally/images/
ErrorLog /usr/home/sally/log/error_log-sally.domain.com8080
CustomLog /usr/home/sally/log/access_log-sally.domain.com8080 common

Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s