< Previous | Contents | Next >
Configuring Virtual Hosts
A virtual host is an extra identity for the web server. The same Apache process can serve multiple websites (say www.kali.org and www.offensive-security.com) because the HTTP requests embed both the name of the website requested and the URL localpart (this feature is known as name-based virtual hosts).
The default configuration for Apache 2 enables name-based virtual hosts. In addition, a default virtual host is defined in the /etc/apache2/sites-enabled/000-default.conf file; this virtual host will be used if no host matching the request sent by the client is found.
Important
Requests concerning unknown virtual hosts will always be served by the first defined virtual host, which is why the package ships a 000-default.
conf configuration file, which sorts first among all other files that you might
create.
Important
Requests concerning unknown virtual hosts will always be served by the first defined virtual host, which is why the package ships a 000-default.
conf configuration file, which sorts first among all other files that you might
create.
Each extra virtual host is then described by a file stored in /etc/apache2/sites-available/. The file is usually named after the hostname of the website followed by a .conf suffix (for example: www.example.com.conf). You can then enable the new virtual host with a2ensite www.example. com. Here is a minimal virtualhost configuration for a website whose files are stored in /srv/www. example.com/www/ (defined with the DocumentRoot option):
<VirtualHost *:80> ServerName www.example.com ServerAlias example.com
<VirtualHost *:80> ServerName www.example.com ServerAlias example.com
DocumentRoot /srv/www.example.com/www
</VirtualHost>
DocumentRoot /srv/www.example.com/www
</VirtualHost>
You might also consider adding CustomLog and ErrorLog directives to configure Apache to output logs in files dedicated to the virtual host.