Creating Multiple Virtual Hosts in Apache2 on Ubuntu

Starting, Stopping, Restarting Apache


1/etc/init.d/apache2 start|stop|restart
Make sure the domain names to resolve to the IP address of your webserver.

nitish.info/etc/apache2/conf.d/virtual.conf


1NameVirtualHost *

/etc/apache2/sites-available -> /etc/apache2/sites-enabled


Create files in /etc/apache2/sites-available, these files should be as below. Then sym link it to same named file in /etc/apache2/sites-enabled


1#
2#  Example.com (/etc/apache2/sites-available/www.example.com)
3#
4<VirtualHost *>
5        ServerAdmin webmaster@example.com
6        ServerName  www.example.com
7        ServerAlias example.com
8
9        # Indexes + Directory Root.
10        DirectoryIndex index.html
11        DocumentRoot /home/www/www.example.com/htdocs/
12
13        # CGI Directory
14        ScriptAlias /cgi-bin/ /home/www/www.example.com/cgi-bin/
15        <Location /cgi-bin>
16                Options +ExecCGI
17        </Location>
18
19        # Logfiles
20        ErrorLog  /home/www/www.example.com/logs/error.log
21        CustomLog /home/www/www.example.com/logs/access.log combined
22</VirtualHost>

1#
2#  Example.net (/etc/apache2/sites-available/www.example.net)
3#
4<VirtualHost *>
5        ServerAdmin webmaster@example.net
6        ServerName  www.example.net
7        ServerAlias example.net
8
9        # Indexes + Directory Root.
10        DirectoryIndex index.html
11        DocumentRoot /home/www/www.example.net/htdocs/
12
13        # CGI Directory
14        ScriptAlias /cgi-bin/ /home/www/www.example.net/cgi-bin/
15        <Location /cgi-bin>
16                Options +ExecCGI
17        </Location>
18
19
20        # Logfiles
21        ErrorLog  /home/www/www.example.net/logs/error.log
22        CustomLog /home/www/www.example.net/logs/access.log combined
23</VirtualHost>