Documente Academic
Documente Profesional
Documente Cultură
Using Apache Virtual Host, you can run several websites on the same server. For example, I can run both thegeekstuff.com and top5freeware.com on a single physical server that has one Apache webserver running on it.
There are two types of Apache virtual host configurations: 1) IP-Based Virtual Host and 2) Name-based Virtual Host. Name-based virtual host is recommended for most scenarios.
NameVirtualHost *:80 Indicates that all the name-based virtual hosts will be listening on the default port 80
<VirtualHost *:80> </VirtualHost> Enclose all the apache configuration parameters for each and every virtual host between these VirtualHost tags. Any apache directives can be used within the virtualhost container. In the following example, we are setting up virtual host for thegeekstuff.com and top5freeware.com listening on the same port 80. So, there will be two <VirtualHost *:80> </VirtualHost>, one for each website. When you go to thegeekstuff.com, the files under /usr/local/apache2/docs/thegeekstuff will be served by Apache; and the access_log and error_log for this site will go under /usr/local/apache2/logs/thegeekstuff
<VirtualHost *:80> ServerAdmin ramesh@thegeekstuff.com DocumentRoot "/usr/local/apache2/docs/thegeekstuff" ServerName thegeekstuff.com ServerAlias www.thegeekstuff.com ErrorLog "logs/thegeekstuff/error_log" CustomLog "logs/thegeekstuff/access_log" common
</VirtualHost>
<VirtualHost *:80> ServerAdmin ramesh@top5freeware.com DocumentRoot "/usr/local/apache2/docs/top5freeware" ServerName top5freeware.com ServerAlias www.top5freeware.com ErrorLog "logs/top5freeware/error_log" CustomLog "logs/top5freeware/access_log" common </VirtualHost>
When something is not configured properly, it will display warning message, including directory does not exit message as shown below.
# /usr/local/apache2/bin/httpd -S Warning: DocumentRoot [/usr/local/apache2/docs/top5freeware] does not exist Warning: ErrorLog [/usr/local/apache2/logs/thegeekstuff] does not exist Syntax OK
Now, when you go to thegeekstuff.com (or www.thegeekstuff.com), the apache will serve the files from /usr/local/apache2/docs/thegeekstuff directory. When you go to top5freeware.com (or www.top5freeware.com), the same apache running on the same server will serve the files from /usr/local/apache2/docs/top5freeware directory. Just to reiterate, for the name-based virtual host to work properly, the DNS entry for both these websites should be pointing to the same external ip-address of the physical server where the Apache webserver is running.