Tech Journal Back to Tech Journal

Virtual Hosts in Apache

Well, I was trying to get the address http://t4c.ma.cx to work. By work I mean to be picked up by my local httpd server, and display the page in /home/shalom/public_html/t4c/ Now, t4c.ma.cx is merely a pointer in ma.cx's DNS records, there is no DNS zone-data on the local machine for t4c.ma.cx. Eventually, I just added the following to the end of /etc/httpd/conf/httpd.conf:

<VirtualHost *>
    ServerAdmin scraimer@softhome.net
    DocumentRoot /home/shalom/public_html/t4c/
    ServerName t4c.ma.cx
</VirtualHost>

That didn't work well with the rest of the the <VirtualHost>, since the ones in the begining of the file kept getting in the way. So I modified the value of NameVirtualHost so that the file also had:

NameVirtualHost *

Now everything seems to work just fine!

Well, it later came to be that I wanted more than 1 virtual host, and it turned out that what I had (above) only worked by not getting in the way. A more correct solution would be to have this in your config:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName www.craimer.org
    ServerAlias craimer.org spinner.craimer.org wpad.craimer.org spc.ma.cx
    DocumentRoot "/var/www/html"
</VirtualHost>

<VirtualHost *:80>
    ServerName shalom.craimer.org
    DocumentRoot "/home/shalom/public_html/"
</VirtualHost>

That'd create both the main host (www.craimer.org) which must be declared, and the second virtual host (shalom.craimer.org).

For more information, see the documentation on the Apache website.

Last updated on 2001-05-26 14:00:00 -0700, by Shalom Craimer

Back to Tech Journal