# How do Apache Virtual Hosts work?

## ZHQ

I've done a somewhat cursory search on the Gentoo website, google, as well as this subforum and a few books as well, but I still seem to be a bit unclear about Apache's virtual host features. I was wondering if anyone could clarify a few things on my comprehensive understanding of how it all works.

By looking around on my current gentoo setup, I see that you have to enable it in the APACHE2_OPTS setting in the /etc/conf.d/apache2 file. There is -D DEFAULT_VHOST and -D SSL_DEFAULT_VHOST already setup for you. So Question 1: Why are all the subsequent settings in this file commented out? I noticed that CONFIGFILE points to /etc/apache2/httpd.conf and that SERVERROOT is also in httpd.conf. Isn't this the file that contains all the "global" settings or something? What is the relationship between /etc/apache2/httpd.conf and /etc/conf.d/apache2?

The settings of a virtual host are contained in files that have <IfDefine NAME> tags? The DEFAULT_VHOST and SSL_DEFAULT_VHOST are defined in the files 00_default_vhost.conf and 00_default_ssl_vhost.conf, repectively. Um, Question 2: Do these files need to have a specific name format (eg, 00_something or ##_something.conf)? Do they have to be in /etc/apache2/vhosts.d? Actually, even better would be if you could tell me what file or parameter specifies where these definitions are searched for.

If you look in the same directory as these files (/etc/apache2/vhosts.d), you can see the default_vhost.include file. Question 3: It also seems to contain documentroot and serverroot settings. Do these override the ones in httpd.conf and other places? It seems to ask once again for the same settings that httpd.conf and /etc/conf.d/apache2 ask for. I noticed that it is included from the default vhost configuration file. Is this necessary or just a readibility thing?

Lastly is the question I want most answered. You can have ip based virtual hosting or name based virtual hosting. The name based virtual hosting seems obvious (I think), that you can have www.sub.domain.com and then www.domain.com appear as two completely different websites, but: Question 4: How does ip based virtual hosting allow a user to request one virtual domain over another?

In the above question, I'm really ignorant about how requests from users is intepreted and/or translated into selecting the different virtual hosts.

Thanks in advance for your attention. Sorry about dumping this huge block of text! (And Merry Christmas and Happy New Year!)

----------

## ZHQ

I found this almost immediately after I finished typing this post. Oops.

http://httpd.apache.org/docs/2.2/vhosts/details.html

 :Embarassed: 

----------

