Google


ADBRITE ads links
You are here: CodeIdol.com > Unix > Linux® Quick Fix > The Apache Web Server > Configuration Multiple Sites And IP Addresses

SAVE
Digg
Shown on del.icio.us del.icio.us
See Whos Talking About This on Technorati Technorati
I've Reddit reddit

Configuration: Multiple Sites and IP Addresses

To help you better understand the edits needed to configure the /etc/httpd/conf/httpd.conf file, I'll walk you through an example scenario. The parameters are:

  • The Web site's systems administrator previously created DNS entries for www.my-web-site.org, my-web-site.org, www.my-web-business.org, and default.my-web-site.org to map to the IP address 97.158.253.26 on this Web server. The domain www.another-web-site.org is also configured to point to alias IP address 97.158.253.27. The administrator wants to be able to get to test.my-web-site.org on all the IP addresses.

  • Traffic to www.my-web-site.org, my-web-site.org, and www.my-webb-usiness.org must get content from subdirectory site2. Hitting these URLs causes Apache to display the contents of index.html in this directory.

  • Traffic to test.my-web-site.org must get content from subdirectory site3.

  • Named virtual hosting will be required for 97.158.253.26 as in this case we have a single IP address serving different content for a variety of domains. A NameVirtualHost directive for 97.158.253.26 is therefore required.

  • Traffic going to www.another-web-site.org will get content from directory site4.

  • All other domains pointing to this server that don't have a matching ServerName directive will get Web pages from the directory defined in the very first <VirtualHost> container: directory site1. Site default.my-web-site.org falls in this category.

Table 20.2 summarizes these requirements.

Table 20.2. Web Hosting Scenario Summary

Domain

IP address

Directory

Type of Virtual Hosting

www.my-web-site.org

my-web-site.org

www.my-web-business.org

97.158.253.26

Site2

Name based

test.my-web-site.org

97.158.253.27

Site3

Name based (Wild card)

www.another-web-site.org

97.158.253.27

Site1

Name based

default.my-web-site.org

All other domains

97.158.253.26

Site1

Name based


How do these requirements translate into code? Here is a sample snippet of a working httpd.conf file:

     ServerName localhost
     NameVirtualHost 97.158.253.26
     NameVirtualHost 97.158.253.27

     #
     # Match a webpage directory with each website
     #
     <VirtualHost *>
         DocumentRoot /home/www/site1
     </VirtualHost>

     <VirtualHost 97.158.253.26>
         DocumentRoot /home/www/site2
         ServerName www.my-web-site.org
         ServerAlias my-web-site.org, www.my-web-business.org
     </VirtualHost>

<VirtualHost 97.158.253.27>
         DocumentRoot /home/www/site3
         ServerName test.my-web-site.org
     </VirtualHost>

     <VirtualHost 97.158.253.27>
         DocumentRoot /home/www/site4
         ServerName www.another-web-site.org
     </VirtualHost>


     #
     # Make sure the directories specified above
     # have restricted access to read-only.
     #
     <Directory "/home/www/*">
         Order allow,deny
         Allow from all

         AllowOverride FileInfo AuthConfig Limit
         Options MultiViews -Indexes SymLinksIfOwnerMatch IncludesNoExec
         <Limit GET POST OPTIONS>
           Order allow,deny
           Allow from all
         </Limit>

         <LimitExcept GET POST OPTIONS>
           Order deny,allow
           Deny from all
         </LimitExcept>

     </Directory>

These statements would normally be found at the very bottom of the file where the virtual hosting statements reside. The last section of this configuration snippet has some additional statements to ensure read-only access to your Web pages with the exception of Web-based forms using POSTs (pages with "submit" buttons). Remember to restart Apache every time you update the httpd.conf file for the changes to take effect on the running process.

Note

You will have to configure your DNS server to point to the correct IP address used for each of the Web sites you host. Chapter 18 shows you how to configure multiple domains, such as my-web-site.org and another-web-site.org, on your DNS server.


Testing Your Web Site Before DNS Is Fixed

You may not be able to wait for DNS to be configured correctly before starting your project. The easiest way to temporarily bypass this is to modify the hosts file on the Web developer's client PC or workstation (not the Apache server).

By default, PCs and Linux workstations query the hosts file first before checking DNS, so if a value for www.my-web-site.org is listed in the file, that's what the client will use.

The Windows equivalent of the Linux /etc/hosts file is named C:\WINDOWS\system32\drivers\etc\hosts. You need to open and edit it with a text editor, such as Notepad. Here you could add an entry similar to:

     97.158.253.26          www.my-web-site.org

Do not remove the localhost entry in this file.

Disabling Directory Listings

Be careful to include any index.html pages in each subdirectory under your DocumentRoot directory, because if one isn't found, Apache will default to giving a listing of all the files in that subdirectory. Say, for example, you create a subdirectory named /home/www/site1/example under www.my-web-site.org's DocumentRoot of /home/www/site1/. Now you'll be able to view the contents of the file my-example.html in this subdirectory if you point your browser to:

     http://www.my-web-site.org/example/my-example.html

If curious surfers decide to see what the index page is for www.my-web-site.org/example, they would type the link:

     http://www.my-web-site.org/example

Apache lists all the contents of the files in the example directory if it can't find the index.html file. You can disable the directory listing by using a -Indexes option in the <Directory> directive for the DocumentRoot like this:

     <Directory "/home/www/*">
       ...
       ...
       ...
       Options MultiViews -Indexes SymLinksIfOwnerMatch IncludesNoExec

Remember to restart Apache after the changes. Users attempting to access the nonexistent index page will now get a "403 Access Denied" message.

Note

When setting up a yum server it's best to enable directory listings for the RPM subdirectories. This allows Web surfers to double-check the locations of files through their browsers.


Handling Missing Pages

You can tell Apache to display a predefined HTML file whenever a surfer attempts to access a non-index page that doesn't exist. You can place this statement in the httpd.conf file, which will make Apache display the contents of missing.htm instead of a generic "404 File Not Found" message:

     ErrorDocument 404 /missing.htm

Remember to put a file with this name in each DocumentRoot directory. You can see the missing.htm file I use by trying the nonexistent link:

     http://www.linuxhomenetworking.com/bogus-file.htm

Notice that this gives the same output as:

     http://www.linuxhomenetworking.com/missing.htm.

    SAVE
    Digg
    Shown on del.icio.us del.icio.us
    See Whos Talking About This on Technorati Technorati
    I've Reddit reddit

    You are here: CodeIdol.com > Unix > Linux® Quick Fix > The Apache Web Server > Configuration Multiple Sites And IP Addresses
       
    Related tags







    Popular Categories
    Unix books and guides
    AJAX popular information
    C# language guides
    Windows books and cookbooks
    .......






    © CodeIdol Labs, 2007