Associate a domain name to a directory in Apache Associate a domain name to a directory in Apache apache apache

Associate a domain name to a directory in Apache


To host multiple domains on the same server with different directories of their own, you need to use the VirtualHost config directive. Inside each one you can specify their own set of configurations (by default the configuration file is stored at /etc/apache2/sites-enabled/000-default.conf):

NameVirtualHost *:80<VirtualHost *:80>        ServerName example.com        DocumentRoot /var/www/site1        <Directory /var/www/site1>            Options -Indexes        </Directory></VirtualHost><VirtualHost *:80>        ServerName another-example.com        DocumentRoot /var/www/site2        <Directory /var/www/site2>            Options +Indexes        </Directory></VirtualHost>

The first one lives in /var/www/site1 and has directory indexing turned off. The other is in /var/www/site2 and has directory indexing turned on. You can specify pretty much most configs to be virtualhost specific - ie, custom logging, use of modules such as php or perl, and ServerAlias, among much more. See http://httpd.apache.org/docs/2.2/mod/core.html#virtualhost for more details.