Official documentation for Apache’s vhost_alias
module can be found at http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html. Some configurations of mass hosting can be also found there – http://httpd.apache.org/docs/2.2/vhosts/mass.html.
Mass virtual hosting is actually quite easy to set up. On Debian you can just put this simple configuration to /etc/apache2/sites-available/vhost
, run a2ensite vhost
and restart Apache server.
<VirtualHost *>
# get the server name from the Host: header
UseCanonicalName Off
# this log format can be split per-virtual-host based on the first field
LogFormat "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vcombined
CustomLog /home/www/logs/access_log vcombined
ErrorLog /home/www/logs/error_log
# add '_' and 'www' symlinks pointing to ./ if you want (in /home/www/doamin.tld/)
# 'www' is not really necessary as it could be a different subdomain
# also does not resolve by IP, have to create symlinks (127.0.0.1 -> 0.1/0)
# it's not pretty but cheap
VirtualDocumentRoot /home/www/%-2.0.%-1.0/%-3
# not used
#VirtualScriptAlias /home/www/%0/cgi-bin
</VirtualHost>
This configuration has some drawbacks but it’s suitable for development workstation or small personal server which can host any number of domains. Subdomains are just directories.
At workstation you can use /etc/hosts
for adding testing domains, no need to configure DNS server.