Using Virtual Hosting

Your Red Hat Linux 6 Apache Web server can easily host multiple sites. The term for this is virtual hosting.

Very heavily visited Web sites need dedicated servers. In fact, it is usual to have a "farm" of many Web servers dedicated to the top 100 Web sites. But the run-of-the-mill Web site—however near and dear it may be to its creator's heart—is very different. It rarely generates enough traffic to use substantial resources on even a single Linux server.

This being the case, those responsible for hosting multiple Web sites—for example, many ISPs—tend to rely on virtual hosting.

To add a virtual host:

1.
Log on as root.

2.
Open the Linux Configuration applet.

3.
In the Apache Web Server section, click Virtual Domains.

The Virtual Domains tab will open ( Figure 14.12 ).

Figure 14.12. Virtual domains can be added, so the your Apache server can host multiple sites.


4.
Click Add.

The Virtual Host Setup tab will open ( Figure 14.13 ).

Figure 14.13. The Virtual Host Setup tab is used for configuring virtual domains served by Apache.


5.
Enter an IP address as the virtual host name.

6.
Enter the server name (the domain name for the virtual site).

7.
Enter a document root for the virtual site. (A document root is file system location used to store the pages that make up the virtual site.)

It is important that each virtual site have a separate document root. Otherwise, you are headed for disorganization and confusion.

8.
If the virtual site will include scripts, enter a script alias.

9.
Enter other options that you want to use.

10.
Click Accept.

11.
When prompted, activate the changes.

Tip

Of course, adding a virtual domain does not give you rights to the domain name. For information on obtaining a domain name and related topics, visit

http://www.internic.net


Using development virtual hosts

Suppose you're in a somewhat different situation. You are not responsible for—and may have no desire to be—hosting multiple sites. But you do want to develop multiple site prototypes, each in its own document root. At some future point, each of these Web sites could be transferred to a host: for example by transferring the files to an ISP or to a business client who has commissioned the site.

In any case, provided you have an IP address for your Linux host, you can easily set up this kind of multiple-development environment. The trick is to use different ports for each virtual site.

Suppose your IP address is 24.6.255.24. You can use this IP for your default Apache site (the one that displays the Apache default start page until you change it). This site can be accessed from your host as http://localhost/ and externally as http://24.6.255.24/ or by using a qualified domain name if one is available—for example,

http://linuxbear.bearhome.com

This site responds to the default port, port 80.

You can then add a virtual site that responds to other ports. For example, one site could respond to port 8080, with a completely distinct document root from the default site. This site would respond to the URL that includes its port: for example,

http://24.6.255.24:8080/

http://linuxbear.bearhome.com:8080/

To add a virtual site that responds to a nondefault port:

1.
Log on as root.

2.
Open the Linux Configuration applet.

3.
In the Apache Web Server section, click Virtual Domains.

The Virtual Domains tab will open.

4.
Click Add.

The Virtual Host Setup tab will open ( Figure 14.14 )

Figure 14.14. You can add virtual sites that respond to nondefault ports to facilitate the development of multiple sites.


5.
Enter a virtual host IP address followed by a colon followed by the nonstandard port number: for example,

24.6.255.24:8080

6.
Enter the server name as the IP address followed by a colon followed by the nonstandard port number: for example,

24.6.255.24:8080

7.
Enter a document root that is distinct for this particular virtual site: for example,

/www/linuxbear

8.
Enter any other options you want.

9.
Click Accept.

10.
When prompted, activate the changes

11.
In a text editor, open the Apache configuration file /etc/httpd/conf/httpd.conf ( Figure 14.15 )

Figure 14.15. To add a virtual site using a nonstandard port, you must make sure that Apache is listening on the port.


12.
Add a line to the configuration file directing Apache to listen on port 8080:

Listen 24.6.255.24:8080

This line should go right beneath other Listen directives in the file.

For more information on the Apache configuration file, see "Using Apache Configuration Directives" later in this chapter.

13.
Save the changes to httpd.conf.

Tip

Ports can be any number between 0 and 65535. However, all port numbers below 1024 are already assigned to specific services such as FTP, telnet, and so on. (You can view the list of port-to-service assignments in the /etc/services file.) It is safest to pick a port above 8000 as the nonstandard port.


You are now ready to test the virtual site. First, create a file named index.html containing some basic HTML along these lines:

<html>
  <head>
    <title>Kingdom of the Sierras</title>
  </head>
  <body background="harold.gif" link="white">
  <h1&>
  <center><font size=7>
                 Kingdom of the Sierras</font>
  </center>
  </h1><BR>
  <table cellpadding=80 cellspacing=4>
  <tr&>
  <td><font size=5>
  <a href="">Maps of the High Country</a><br>
  <a href="">Lakes like jewels</a><br>
  <a href="">Freedom of the hills!</a><br>
  <a href="">
       Stars like diamonds in the night sky!</a><br>
  <a href="mailto:[email protected]"
       Contact the Bears
       </a>
       </font>
  </td><td></td>
  <td><br></td>
  </tr>
  </table>
  </body>
</html>

To test the virtual site:

1.
Copy the file index.html that you just created, along with any graphics files that it requires, to the virtual host document root, /www/linuxbear.

2.
In a Web browser, enter the URL for the virtual site, including the port:

http://24.6.255.24:8080/

The test page that you just created will be displayed ( Figure 14.16 ).

Figure 14.16. You can invoke the virtual host by adding its nonstandard port number to the URL.


3.
Make sure that the IP address with the standard port, http://24.6.255.24/, still displays the Apache default start page.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.232.11