Question: Virtual Domain Hosting Virtual hosting involves using one server to host multiple web sites for multiple domains. For example, let's say that you have a

Virtual Domain Hosting

Virtual hosting involves using one server to host multiple web sites for multiple domains. For example, let's say that you have a business with the domain name elvis4ever.com and the Web site www.elvis4ever.com. Let's say your sister has the domain name jamesdeanlives.com and wants to set-up a Web site www.jamesdeanlives.com. Rather than set-up another server for her, you could create a virtual host on your existing server. Apache will know what pages to use based on the url, so the user will never know that both sites (or more) are on the same machine.

Virtual hosting can be done with sites that have different IP addresses or with the same IP address. The configuration is only slightly different, and we are going to focus on sites with the same IP address. For additional information on this topic, look at http://httpd.apache.org/docs/2.2/vhosts/index.html.

Step 1: Configuring httpd.conf

The last section of the httpd.conf file includes the following lines:

# Virtual hosts #Include conf/extra/httpd-vhosts.conf

uncomment the #Include line, httpd-vhosts.conf is the configuration file that you will be working with to address virtual hosts. You will find this file one directory below where your httpd.conf file is (in the "extra" directory).

The first thing we want to do is make a backup copy of httpd-vhosts.conf, save it as httpd-vhosts.sv.

You will see the following line:

NameVirtualHost *:80 or NameVirtualHost *:8080

This directive tells Apache what IP addresses at which it will receive virtual hosts requests. The * is a wildcard for all IP addresses. You could also put in the IP address of the server.

The next step is to create a virtual host block (you will see some that already exist in this file):

ServerAdmin webmaster@dummy-host.example.com DocumentRoot /www/docs/dummy-host.example.com ServerName dummy-host.example.com ErrorLog "C:/Program Files/Apache Software Foundation/Apache2.2/logs/dummy-host.example.com-error_log" CustomLog "C:/Program Files/Apache Software Foundation/Apache2.2/logs/dummy-host.example.com-access_log" common < /VirtualHost>

Virtually any Apache directive can be used within this block. This example shows that a virtual host will be used for a request that is an unknown domain name. In this example, the virtual host is dummy-host.example.com. You can see that the DocumentRoot is different than the main server, and separate log files will be created. Any settings in the block will override settings for the main server.

When Apache receives a request at the IP address listed in NameVirtualHost, it will look to see if the server name matches a virtual host. If no match is found, the first virtual host in the list will be used. To insure that the default pointed to your main server, you would have to do something like this:

ServerName localhost.com DocumentRoot /Apache2.2/htdocs/

ServerAdmin webmaster@dummy-host.example.com DocumentRoot /www/docs/dummy-host.example.com ServerName dummy-host.example.com ErrorLog "C:/Program Files/Apache Software Foundation/Apache2.2/logs/dummy-host.example.com-error_log" CustomLog "C:/Program Files/Apache Software Foundation/Apache2.2/logs/dummy-host.example.com-access_log" common < /VirtualHost>

With this configuration, any requests for dummy-host.example.com will go to the virtual host for that server, and all other requests will go to the main server.

We can also use virtual hosts to support more than one server name for the server using a ServerAlias directive:

ServerAlias example.com *.example.com ServerName www.example.com DocumentRoot /Apache2.2/htdocs/

This configuration shows that urls for example.com, www.example.com, web.example.com, and anything else xxx.example.com will be handled by www.example.com. (You would also have to have your domain name service configured to make this happen, but it is a useful capability.)

For your assignment:

Turn on virtual hosting on your server

Create a default virtual host that points to your main server

Create a new host with the following configuration:

ServerName is www.secondhost.com

The server's documents should be stored in the directory: /Program Files/Apache Software Foundation/Apache2.2/secondhost

The virtual host has its own log files

The default setting for directories on this server should not allow SymLinks, ExecCGI, or Includes

Step 2: Testing Your Configuration

Because you do not have access to domain name service, you can not really test this configuration. What you can do is start Apache with the -S flag to see a different type of configuration check that can be useful in debugging virtual host problems.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!