Virtual Hosting on Apache httpd - a primer example
Archive - Originally posted on "The Horse's Mouth" - 2008-06-25 09:16:11 - Graham EllisA single web server computer, running a single Apache httpd daemon, can serve many domains through virtual hosting - usually "named virtual hosting" which allows a single IP address to be used for all the different domains.
Here is how it works ...
• you set up all your defaults in the main httpd.conf file
• your FIRST virtual host contains everything that differs from these defaults for hosts that are not otherwise defined in any later virtualhost blocks, and also for any requests that do not include a host name.
• subsequent virtual host blocks provide the changes from the initial defaults for specific hosts or hosts, as specified by the servername directive(s) within each block.
Here's an example of the end on an httpd.conf file
NameVirtualHost *:80
#
<VirtualHost *:80>
</VirtualHost>
#
include conf/stuffing.txt
#
<VirtualHost *:80>
ServerName www.hussey.co.uk
DocumentRoot /home/hussey/html
CustomLog /home/hussey/logs/villagepeople.log combined
</VirtualHost>
all host names are served by the defaults, except www.hussey.co.uk which has a different document root and log file. There's also probably another virtual host included in stuffing.txt ....
<VirtualHost *:80>
ServerName www.royaloak.waddy
DocumentRoot /home/royaloak/html
CustomLog /home/hussey/logs/villagepeople.log combined
</VirtualHost>
Yes - the domain www.royaloak.waddy is also served from a different directory.
Above example from yesterday's Linux Web Server course