Recipe 12.4. Hosting Multiple Web SitesProblemYou want to host multiple web sites on the same computer. SolutionUsing a graphical user interfaceTo uniquely identify each web site by IP address:
To uniquely identify each web site by port number:
To uniquely identify each web site by host header name:
You can also modify the IP address or port number of an existing web site, or assign it a host header name, by doing the following:
Using a command-line interfaceThe following commands create two web sites on the local server that are uniquely identified by IP addresses: > iisweb /create D:\HR "Human Resources" /i 172.16.12.51 > iisweb /create D:\Finance "Accounting Department" /i 172.16.12.52 The following commands create two web sites on the local server that are uniquely identified by port numbers (the first site uses the default port 80): > iisweb /create D:\HR "Human Resources" /i 172.16.12.50 > iisweb /create D:\Finance "Accounting Department" /b 8080 /i 172.16.12.50 The following commands create two web sites that are uniquely identified by their host header names: > iisweb /create D:\HR "Human Resources" /i 172.16.12.50 /d hr.mtit.com > iisweb /create D:\Finance "Accounting Department" /i 172.16.12.50 /d acct.mtit.com To list all web sites on the local server, use the following command: > iisweb /query Using VBScript' This code displays all the web sites on a server. ' ------ SCRIPT CONFIGURATION ------ strComputer = "<ServerName>" ' e.g., web01.rallencorp.com ' ------ END CONFIGURATION --------- set objIIS = GetObject("IIS://" & strComputer & "/W3SVC") for each objSite in objIIS if (objSite.Class = "IIsWebServer") then WScript.Echo objSite.ServerComment & " (" & objSite.Name & ")" end if next DiscussionThe maximum number of web sites you can create on an IIS 6 computer depends on the available RAM. For example, a computer with 256 MB of RAM can host only 64 sites, and if you try to create a 65th site you'll get error 1131 in the System event log. In lieu of adding more RAM, you can work around this limitation by creating a new DWORD value named MaxEndPoints in the following registry key: HKLM\SYSTEM\CurrentControlSet\Services\HTTP\Parameters Set MaxEndPoints to one more than the number of web sites you need to host, but don't exceed 1024.
Using VBScriptThis code works by obtaining a reference to the top-level IIS service (W3SVC), enumerating all of the child objects, and printing the child objects of the class IIsWebServer, which represent web sites. The W3SVC object can also have IIsWebInfo and IIsFilter child objects, so if you don't check for the IIsWebServer class, you may end up printing more than just web sites. See AlsoRecipe 12.3 and MS KB 324287 (HOW TO: Use Host Header Names to Configure Multiple Web Sites in Internet Information Services 6.0) |