KB: Apache Virtual Host Setup on Ubuntu

Apache Virtual Host Setup on Ubuntu Linux.



This is not a definitive guide on configuring Apache virtual servers, but rather a step-by-step on what works for me. This article assumes that you already have Apache installed on your system and that you are using a single IP address.

Define Virtual Hosts

1. Disable Ubuntu default web site:

rm /etc/apache2/sites-enabled/000-default

2. Create directory ‘newsite’ under /var/www e.g. /var/www/newsite

mkdir /var/www/newsite

3. Create file /etc/apache2/sites-available/zunisoft:

NameVirtualHost *:80

<virtualhost _default_:80>
       RedirectMatch ^/$ http://www.zunisoft.com/

<virtualhost *:80>
        ServerName www.zunisoft.com
        ServerAdmin webmaster@zunisoft.com

        DocumentRoot /var/www/wordpress

        DirectoryIndex index.html index.php

        <location awstats>
                SetHandler cgi-script
                Order deny,allow
                Deny from all
                AuthName "Web Statistics Login"
                AuthType basic
                AuthUserFile /etc/apache2/passwd
                Require valid-user
                Satisfy any

                Options FollowSymLinks
                AllowOverride None

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

        <directory /usr/lib/cgi-bin>
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all

        ErrorLog /var/log/apache2/www.error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/www.access.log combined
        ServerSignature On

    Alias /doc/ "/usr/share/doc/"

    <directory /usr/share/doc>
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from ::1/128

4. Create the following links in /etc/sites-enabled (000 makes this site the default as it will load first, use 001, 002 to control load order for other domains):

ln -s /etc/apache2/sites-available/zunisoft 000-zunisoft

5. Restart Apache:

/etc/init.d/apache2 restart

To Top

Leave a Reply

Your email address will not be published. Required fields are marked *