Monday, April 20, 2009

Configuring IIS 6 to use Host Headers

IIS 6 can be setup to host mutiple websites using the same IP address using Host Headers. If the site only runs on port 80 (i.e. only uses http:// not https://) this can be setup using the Internet Information Services (IIS) Manager's "Advanced Web Site Identification" dialog. If one or more of the websites hosted on the IP address uses port 443 (i.e. https:// or SSL), the Host Headers must be configured using a command line tool.

Configuring Server Bindings for SSL Host Headers (IIS 6.0)

1. Open a Command Prompt window and change to the %SystemDrive%\Inetpub\AdminScripts directory.
2. Enter the following command to get a list of websites hosted by this server:

cscript.exe adsutil.vbs ENUM /P /W3SVC/

You should see something like the following:
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

[/W3SVC/AppPools]
[/W3SVC/Info]
[/W3SVC/1]
[/W3SVC/Filters]
[/W3SVC/260116085]
[/W3SVC/2123871385]
[/W3SVC/721699136]
 
To determine which the name of each website, enter the following command:

cscript.exe adsutil.vbs ENUM /W3SVC/<site identifier>/

Where <site identifier> is the number of the site to check. You should see something like the following:
 
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
 
KeyType                         : (STRING) "IIsWebServer"
ServerState                     : (INTEGER) 2
ServerComment                   : (STRING) "GenerationsUnite"
ServerAutoStart                 : (BOOLEAN) True
ServerBindings                  : (LIST) (2 Items)
  "192.168.64.7:80:www.mysite.com"
  "192.168.64.7:80:mysite.com"
 
SecureBindings                  : (LIST) (2 Items)
  ":443:www.mysite.com"
  ":443:mysite.com"
 
AuthFlags                       : (INTEGER) 0
Win32Error                      : (INTEGER) 0
[/W3SVC/260116085/filters]
[/W3SVC/260116085/root]
 
3. To setup an SSL Host Header binding, enter the following command:

cscript.exe adsutil.vbs set /w3svc/<site identifier>/SecureBindings ":443:<host header>" [<additional bindings>]

The following is an example that sets up two bindings for a website:

cscript.exe adsutil.vbs set /w3svc/260116085/SecureBindings ":443:www.mysite.com" ":443:mysite.com"