risley.netVirtual Hosting (Personal Web Sharing Version)



What it Does

Virtual Hosting (often called "multihoming" or "IP Sharing") allows you to host several different domains from a single IP address. This saves IP address space, which is in somewhat short supply these days. It is also useful for the webmaster operating from a home DSL line or other service where only a single IP address is provided. You can usually purchase additional IP addresses from your ISP, but this script (being free) is more economical.

This script works by redirecting anyone looking for the default home page of a domain to a different URL based on the host name supplied with the request. How that helps you implement IP sharing may not be obvious at first, so let's use my site as an example.:

What You Need

What You Do

Say you want to host two different websites with two different domains from a single IP address: www.risley.net and www.guerillaphysician.com.

How it Works

When you point a browser to a domain without a specific path, the web server usually looks for a default file to serve. In the case of Personal Web Sharing, that file is named "index.html". We have created an "index.html" file that tells the browser to open another file, "index.acgi". Personal Web Sharing sees that it isn't an .html file but a .cgi script, so it executes it instead of opening it.

The script looks at the hostname in the request and, using the table you create in the domTrans property, obtains a new URL. If you put each domain in a separate folder on your site, it appears to the user that each domain is hosted on a separate machine (though if they look carefully at the URLs for individual pages, they'll see that all pages on a given site are in a subdirectory).

An Even Better Way

One problem with this approach is that we do too many redirects. The first one is particularly slow and ugly, since it relies on a META refresh tag. Some very old browsers don't support it, and most (if not all) of the ones that do will display the redirection page briefly before loading the target page.

There is a nifty way around that, though it requires some hacking. Make a copy of the File Sharing Extension. Store it in a safe place. Using a file editor, open the data fork of the File Sharing Extension in your Extensions folder. Search for the string "index.html" and replace it with "index.acgi". Now, requests to the home directory of any of your domains will automatically execute the virtual hosting script without having to first load the "index.html" page.

An even cleaner solution exists if you use NetPresenz as your server. This server also gives you FTP service and a Gopher server. My missing.acgi for NetPresenz provides a slightly more advanced form of IP sharing. (Note that NetPresenz is no longer shareware, is quite expensive, and apparently is unsupported as longstanding bugs have gone unaddressed.)

Other Information

I wrote an article in TidBITS on using the Macintosh as an inexpensive Internet server platform. The response to that article prompted my posting this page. It is called Serving the Internet from a PowerBook 5300, and is available online.

If you have comments, problems, or suggestions, please feel free to email me. I'll answer as soon as I can, but remember that I don't have gobs of time to provide technical support for free software.

Thanks for your interest and support!


risley.net

Date created: July 1, 2000
Last modified: July 4, 2001
Copyright © 2000 Ron Risley

risley.net webmaster