Configuring the first IIS 7.x box is far easier than IIS 6 was, but configuring multiple web servers to behave identically can be a pain. Web Farm Framework (available in Web Platform Installer) can automatically synchronize things, but these settings change so rarely, and changes need to propagate immediately that I’d rather do this manually. Well, constructing the 3rd or 4th or nth machine gets old. Can we make this easier? Most definitely we can.
Back in the IIS 6 days, the “IIS Metabase” was a scary thing — like modifying the registry or getting surgery. Granted, we did this every day, but it was always daunting. In IIS 7, the entirety of the IIS configuration details are in xml in C:WindowsSystem32inetsrvconfigapplicationHost.config (unless they’re overridden in each site’s web.config). How do you set up machine 2 to behave exactly as machine 1? You diff the files and copy nodes. Yeah, no more surgery. Awesome.
Ok, setting up IIS #2 isn’t quite as simple as diffing the files, but it’s pretty close. Here’s a rough checklist of things I do to make machine 2 function identically to machine 1:
1. Install IIS on each machine
2. Install any plugins / extensions on each machine – typically this is merely a trip through Web Platform Installer
3. Configure Machine 1 to be perfect
4. Backup C:WindowsSystem32inetsrvconfigapplicationHost.config on both machines — it’s easy to mess up, and running without a safety net is bad
5. Diff C:WindowsSystem32inetsrvconfigapplicationHost.config between the two machines, and begin noticing the differences
6. Copy changes from machine 1 to machine 2
7. Restart IIS or reboot (you probably haven’t rebooted since installing Windows Updates) — probably not essential, but best not to get started on the wrong foot
As we’re diffing applicationHost.config we’ll see a few things that we can merge, and a few things that must stay different. Let’s look through a few sections:
- <configProtectedData> node has AesProvider and IISWASOnlyAesProvider nodes. These include machine-specific details. If you accidentally merge these details between the two machines, go to your backup and get the original details back. I’ve never personally hosed a box by doing so, but I’ve also treaded very carefully here.
- <system.applicationHost><applicationPools> node includes one node per app pool. Do you always set them to 4.0, startMode=”AlwaysRunning” or anything else interesting? It isn’t 3 or 5 clicks away, it’s just a text file change now. Be careful not to merge an identity password though — it’s machine-specifically encrypted. Just merge in all the app pools from Machine 1 into place.
- <system.applicationHost><sites> node includes one child <site> node per website. You can configure everything here just by adding attributes and child nodes. Or add a complete site by merging in another <site> node. (Be careful to insure their id=”" are unique and that they reference an applicationPool that exists.) Just merge in all the sites from Machine 1 into place.
- <system.webServer><globalModules> includes a list of all the httpModules installed into IIS. Depending on what order you clicked the check-boxes while installing IIS or what order Web Platform Installer installed plugins, these may be in different orders between the machine. Provided you don’t add or remove nodes, you can reorder them for “cleanliness”.
- <location path=”…”> nodes at the bottom alter authentication protocols for each site. You can do similar overloads in web.config, but if you configured it through IIS, they’ll be here. (Alternatively, if you configured it in Visual Studio, the details may only be in that site’s web.config.)
Do you have any other noteworthy nodes in your IIS applicationHost.config files? Any other techniques for configuring IIS with ease?