Apache: Name Based Hosting |
Server Training - Web Server |
There are basically two possibilities for Virtual Hosting. One is Name Based Hosting which uses one IP Address for all of the domains that are on the server. Once a domain name is registered and setup the web server will serve the correct domain name despite being on the same IP Address. IP based hosting requires a separate IP Address for each server. This tutorial will help you set up the Name Based Hosting on an Apache Web Server. If you want to learn about Ubuntu Name Based Hosting CLICK HERE. The reason is that Ubuntu and CentOS are configured differently. The documentation on this page is for centOS. In order to use Name Based Hosting you will need to use the NameVirtualHost directive and supply the IP Address, this must be a public IP Address for the Internet. The VirtualHost directives enclose each virtual host: Configuration Directives <VirtualHost 192.168.5.64>
</VirtualHost> Used to enclose a group of directives that will impact only one virtual host.
Each Virtual Host must correspond to a different IP address, different port number or a different host
Live Class Descriptions:
Here is an example of several named based setups. NameVirtualHost 192.168.5.56 ###note this is a private IP Address in the example <VirtualHost 192.168.5.56> DocumentRoot /var/www/htdocs/webone/html ServerName www.webone.com ErrorLog /var/www/htdocs/webone/logs/error_log </VirtualHost>
<VirtualHost 192.168.5.56> DocumentRoot /var/www/htdocs/webtwo/html ServerName www.webtwo.com ErrorLog /var/www/htdocs/webtwo/logs/error_log </VirtualHost> There are several parts to note with Named Based setups. DocumentRoot is the location on the server where the main documents or web pages for the domain must be placed. The example shows: /var/www/htdocs/webone/html /var/www/htdocs/webtwo/html This DocumentRoot directory must be declared in this directive. It could be other places on the server, for example: /user/local/htdocs/webone or /home/webone/htdocs/webone The important thing to do is create a pattern so you can place these directories in a partition or directory that can be backed up and it is easier to configure. PLAN AHEAD When the server is created you must know where you will locate the web services. If the /var directory will be used it must be large enough to hold all of the web services as well as a large number of growing logs. If the /usr/local directory will be used it too must have the resources to grow to the organization’s needs. The ServerName is also important to declare in the directive. The domain name for the specific server must be declared. This declaration may be with the www included or not. The ErrorLog determines where the errors for a specific domain will be located. It is most valuable to have logs in the same directory as the domain. Place the logs directory at the same level as the html directory. Here is an example: /var/www/htdocs/myserver1/html /var/www/htdocs/myserver1/logs/ Typically, logs are placed in /var/log/httpd unless you have a number of virtual hosts which you may want the logs to be separate then. It is often safer to not place the logs directory in the same directory as the html pages that users will view. This mainly reminds you that the logs directory should not be read by any user except apache. The actual http.conf or apache2.conf if you are using Ubuntu 8.04 section for Virtual Hosts is listed below.
### Section 3: Virtual Hosts # # VirtualHost: If you want to maintain multiple domains/hostnames on your # machine you can setup VirtualHost containers for them. Most configurations # use only name-based virtual hosts so the server doesn't need to worry about # IP addresses. This is indicated by the asterisks in the directives below. # # Please see the documentation at # <URL:http://httpd.apache.org/docs/2.2/vhosts/> # for further details before you try to setup virtual hosts. # # You may use the command line option '-S' to verify your virtual host # configuration.
# # Use name-based virtual hosting. # #NameVirtualHost *:80 # # NOTE: NameVirtualHost cannot be used without a port specifier # (e.g. :80) if mod_ssl is being used, due to the nature of the # SSL protocol. # # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for requests without a known # server name. # #<VirtualHost *:80> # ServerAdmin This e-mail address is being protected from spambots. You need JavaScript enabled to view it # DocumentRoot /www/docs/dummy-host.example.com # ServerName dummy-host.example.com # ErrorLog logs/dummy-host.example.com-error_log # CustomLog logs/dummy-host.example.com-access_log common #</VirtualHost> Copyright CyberMontana Inc. and BeginLinux.com All rights reserved. Cannot be reproduced without written permission. Box 1262 Trout Creek, MT 59874
|