April 3, 2008, 12:16 p.m.
posted by whitehat
Configuration: Multiple Sites and IP AddressesTo 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:
Figure summarizes these requirements.
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. Testing Your Web Site Before DNS Is FixedYou 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 ListingsBe 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.
Handling Missing PagesYou 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.
|
- Comment