The Microsoft Windows IIS webserver can be challenging sometimes. We can easily think up things we want to do with it that require some work. Case in point – I want to be able to have multiple IIS entries all point to the same physical directory on my hard drive.
First, what do I mean by IIS entries? Terminology can be tough. What I mean is, in IIS terms, sites. A “site” in IIS can actually hold multiple website names in it, which is why I find that term a bit problematic. They look like this:
So for example one of their “sites” is my entry for bellaforums. That actually holds the information for forums.bellaonline.com, forum.bellaonline.com, and f.bellaonline.com. So the IIS “sites” designation is for one collection of URLs. They can have multiple subdomains or even entirely different website URLs as part of their definition.
Another “site” entry is bellaonline.com. That holds the information for www.bellaonline.com, asp.bellaonline.com, quilting.bellaonline.com, and so on.
Why Create Multiple IIS Sites Pointing to One Subdirectory?
Normally, pre-secure-server, I would just make one wildcard entry in the BellaOnline site which covered *.bellaonline.com. That way visitors could type birding.bellaonline.com or rap.bellaonline.com and get to the site. I could then handle what they were shown programatically.
However, the secure server software I use – LetsEncrypt – is tricky to use with wildcards. It’s both challenging to set up and then also challenging to maintain. So after several runs at it, I decided to go with listing each subdomain individually. I have about 450 so it’s a one-time setup to go through and then I’m done.
However, LetsEncrypt also has a limit of 100 entries per certificate. So I don’t want to stuff all 450 certificates into a single IIS Site. I want to have a main site with the first 100 subdomains. Then a second “site” (again, in IIS terms) with the next 100 subdomains, and so on.
In an ideal world, all of these “sites” in IIS would point to my exact same c:\bellaonline folder which holds the content. However:
IIS Sites Store IIS Attributes in Web.Config In Main Directory
If you’ve used IIS, you’ve probably seen the web.config file appear in the main directory for each site you work on. This is how IIS stores its information. It doesn’t store it in some system folder area. It stores the information you enter in the actual live folder you point to for your data. So if my website content lives on my hard drive in c:\bellaonline, I then get a web.config file at that top level directory.
That is fine if you have just one site you are managing that uses that directory. But if you have multiple sites in IIS? Now they are both trying to use that same web.config file to store their details. If you change it for one, you’re actually changing it for all of them.
If you look again at the way I have my sites set up in IIS:
You can see that I have a site set up called bellaonline-redir. This is so when someone types in bellaonline.com (without the www) it properly redirects them to www.bellaonline.com which is how I have my main site defined. I do this as a separate site entry. Because of that, I also have a folder on my hard drive called c:\redirs\bellaonline\ which I point that bellaonline-redir to. That way the web.config file for that redirection is wholly separate from the web.config file for my main bellaonline.com site.
So in this case, where I want multiple site entries in IIS to point at a single physical directory on my hard drive, and only 100 subdomains in each site entry, I do this by creating more sites which actually point at their own subdirectories for web.config reasons. You can see on here that I created a site called bellaonlinesub2-redir – and it points at c:\redirs\bellaonlinesub2. This holds set #2 of my subdomain list. Let’s say it is from folkmusic.bellaonline.com to quilting.bellaonline.com. It’s the second 100 subdomains in my list. It stores its web.config in its own c:\redirs\bellaonlinesub2 folder so that its web.config is its own.
I also set it to log in its own logging directory, so I can track its activities separately.
I then set up the redirect so that it sends its traffic to the main bellaonline.com site. That way visitors see the bellaonline.com site.
This then allows me to set up the LetsEncrypt entry for that site #2 as its own certificate, quickly and easily. I simply point at that site and it creates a certificate for all 100 subdomains which belong to that site. It easily initializes the secure certificate and easily renews it as well.
Ask with any questions!
Leave a Reply