Hosting Multiple Sites using IIS

If you’re the “IT guy” at a small company, you’re sometimes asked to do things you’ve never done before. This usually involves setting up a new piece of hardware or software, configuring it, then leaving it alone. Every once in a while, however, you’ll come across a true noodle-scratcher… such as how to use one Windows server to host multiple web sites. At first glace, it might seem impossible. After all, most websites run on port 80, and you can only forward port 80 to one server on your network. So even if you wanted to host the sites on two different servers, you couldn’t with most SOHO routers. You could always run one of the sites on a different port, but then visitors that type http://www.companyname.com into their web browsers won’t know to add :8080 at the end of the address and so they won’t get your home page. Telling employees to always add :8080 to the intranet address isn’t much of a solution either, as non-technical folks won’t understand why they need to do this, and will call you up, angry as hell, since they can’t get to the company intranet.

So how do you host multiple sites with one address? By using host headers. All 3.0 and higher web browsers use the HTTP 1.1 protocol. In version 1.1 the requesting browser sends the hostname to the server during its initial request. In other words, the browser essentially says “hey 192.168.1.1… I’m 192.168.1.3 and I’m looking for companyname.com. Is that here? If so, send me the webpage.” Host headers take advantage of this protocol, and redirect each HTTP request to the appropriate site in your local IIS installation.

To set up host headers, open the IIS Manager (Start > Administrative Tools > IIS Manager) and right-click each website you’re hosting and select “Properties”. On the “Web Site” tab, click the “Advanced” button under “Web Site Identification”. In the next window, click the “Add” box under “Multiple Identities For This Website”. In the box that appears, leave “IP Address” at “All Unassigned”, type the port number (the default is 80) under “TCP Port” and then type in the domain name you wish to use with the site under “Host Header Value”. Click “OK” when done. Click “OK” again at the “Advanced Website Identification” box (or add additional domains, if you want to redirect additional domains to the same site, i.e. your company also own the .net and .biz domains and wants those to be sent to the main .com website). Repeat this process for every site hosted on the local server. Now when visitors come to your sites, their web browsers will tell IIS which site to serve that particular user.

There is one minor caveat to using host headers, however. Under the HTTP 1.0 protocol, host headers are *not* included in the initial request. The browser simply says “hey 192.168.1.1… I’m 192.168.1.3! Please send me the webpage you’re hosting, please!” Depending on which site you have configured without host headers, or which site you have selected as default, anyone using Internet Explorer 2.x or Netscape 2.x will get that site instead of whichever one they actually want. Now, going from this website’s statistics, NO ONE is using a 2.x browser (I don’t think I’ve ever even seen a 2.x hit), so it’s probably not a big problem… But it’s something to consider.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.