Wednesday, August 24, 2011

IIS7 and easy configuration of SSL host headers

If you ever tried to configure SSL host headers for your IIS7 sites, you already know that this can be done from the IIS management console only for the very first site. If you try to add the SSL binding for another site, the console will prevent you from doing so.

How people usually solve this problem is they use the appcmd commandline tool to add the SSL binding manually for other sites. First, you map add SSL to the very first of your sites manually and then use a script to map another site:

appcmd set site /site.name:"thesitename" /+bindings.[protocol='https',bindingInformation='*:443:host.header.value.com']

However, there’s actually much simpler way to add the SSL binding. It involves manually editing the IIS configuration file, which is C:\Windows\System32\intersrv\config\applicationHost.config. The IIS uses this file to store its configuration.

Edit this file, find a <site> node which refers to your site, it should look like this:

<site name="thesitename" id="3" serverAutoStart="true">
      <application path="/" applicationPool="thepoolname">
          <virtualDirectory path="/" physicalPath="C:\inetpub\somepath" />
      </application>
      <bindings>
          <binding protocol="http" bindingInformation="*:80:host.header.value.com" />
      </bindings>
</site>

Just modify this to:

<site name="thesitename" id="3" serverAutoStart="true">
      <application path="/" applicationPool="thepoolname">
          <virtualDirectory path="/" physicalPath="C:\inetpub\somepath" />
      </application>
      <bindings>
          <binding protocol="http" bindingInformation="*:80:host.header.value.com" />
          <binding protocol="https" bindingInformation="*:443:host.header.value.com" />
      </bindings>
</site>

You can quickly and easily modify all of your sites this way. Then, restart IIS and you are done.

No comments: