Ubuntu Gutsy - Apache Virtual Hosts #2

The previous Ubuntu Gutsy Apache Virtual Hosts article introduced the basics of the setting up virtual hosts.

This allowed us to serve multiple domains from a single IP address and Slice. Now we can look in detail at the settings available to us in the Virtual Hosts files and introduce some new ones.



ServerAdmin webmaster@domain.com

Sets the email address for the server administrator - this will be used if you have setup the server to contact you on errors. It is also shown in the ServerSignature (if set to 'On' - see below)

Domain Name

ServerName and ServerAlias

ServerName domain.com
ServerAlias www.domain.com

Sets the domain name for the virtual host. You can have as many aliases as required.

Index Files


DirectoryIndex index.html

Defines the index file (the 'home' page that is shown on entering the domain address). Useful if you have want the user to be directed to an alternate page or to a non-standard home page.

Do note this is not a good way of redirecting users as they may go directly to a non specified page such as http://domain.com/index.php whilst the DirectoryIndex will only work for those entering http://domain.com.



DocumentRoot /home/demo/public_html/domain.com/public

The location of the domain's public files. Use an absolute path name.

Log Files

ErrorLog and CustomLog

LogLevel warn
ErrorLog  /home/demo/public_html/domain.com/logs/error.log
CustomLog /home/demo/public_html/domain.com/logs/access.log combined

Set the Log levels and the location for the Virtual Hosts log files. Very useful for easy analysis of the domain statistics.

Error Documents


ErrorDocument 404 /errors/404.html
ErrorDocument 403 /errors/403.html

Used for all the standard error messages.

In these examples I have an 'errors' folder in my public directory. I created each error document and place them in the 'errors' folder. The paths shown are relative to the DocumentRoot folder defined above.

If not defined, the default Apache generated error pages will be shown.

Apache Footers


ServerSignature On

Sets whether the server details are displayed in any server generated error pages or index lists. Options are On, Off and Email.

Note that the signature details are configured via ServerTokens which cannot be set in the Virtual Hosts file - only in the main apache2.conf. See here for more details.

If set to Email, the ServerAdmin email will be displayed.



ScriptAlias /cgi-bin/ /home/demo/public_html/domain.com/cgi-bin/
<Location /cgi-bin>
  Options +ExecCGI

Enables the cgi-bin location as defined by the custom virtual hosts layout. You can, of course, leave the cgi-bin in the DocumentRoot location if you so wish.


<Directory xxx/xxx>

<Directory /home/demo/public_html/domain.com/public>
  Options FollowSymLinks

Set the Options for the specified directory - the example shown allows the Option FollowSymLinks to be enable for the public directory of domain.com

Listed below are further Options that can be set:

Directory Browsing


Options -Indexes

To turn off directory browsing use '-Indexes' or 'None'. To turn them on, use '+Indexes'.



Options -Includes

This Option disables Server Side Inlcudes.



Options -FollowSymLinks

Enable or disable the option to follow symlinks. Be careful with this option as it can lead to security risks (inadvertently linking to configuration folders).



AllowOverride None

Setting AllowOverride to none disables .htaccess support. Set to All to allow them.

You can also specify which .htaccess features to enable such as:

AllowOverride AuthConfig Indexes

The Apache AllowOverride docs has more information on the different features.

Remember to specifically protect your .htaccess file. This can be done in two ways:

Firstly rename it to something obscure and, secondly, deny access to the file from external sources:

AccessFileName .myobscurefilename
<Files ~ "^\.my">
    Order allow,deny
    Deny from all
    Satisfy All

No Options


Options None

This will turn off all the available options.


Remember that the Options directives can be set per directory like this:

<Directory />
  AllowOverride None
  Options None

<Directory /home/demo/public_html/domain.com/public>
  AllowOverride All

This will turn of all Options and disable .htaccess support for all directories.

However, the second Directory setting will override the first and allow .htaccess support for the domain.com/public directory.


The Virtual Hosts file is at once an easy tool to use and a very powerful one. My advice is to enter one setting and test it. Then enter the next setting and so on.

Once familiar you will see you have fine control over all of your web folders and files.


Article Comments:

Sip commented Mon Jan 21 12:35:34 UTC 2008:

Just wondering if you have a copy of the virtualhost you created/modified in the tutorial available for download? The default that was installed with Apache on my machine seems to differ quite a bit from the one in the tutorial, so I'm not entirely sure if the bulk of the virtualhost I have is needed.

Any help would be appreciated.

PickledOnion commented Mon Jan 21 12:38:35 UTC 2008:


I'm not too sure what you mean to be honest.

The default vhost is located in the /etc/apache/sites-available folder.

The options shown here are ones that you can add or modify for your needs.


Dejay Clayton commented Wed Apr 02 20:48:24 UTC 2008:

Using SymLinksIfOwnerMatch instead of FollowSymLinks is more secure, as it only allows symbolic links to be followed if the owner of the link is identical to the owner of the target file or directory.

Want to comment?

(not made public)


(use plain text or Markdown syntax)