Using Host Headers to host multiple websites on IIS 6.0(Kristofer Gafvert, January 18, 2006)
IIS 6.0 is capable of hosting multiple websites on one server. This is done by separating the websites with unique combinations of host header name, IP number and port. This article will explain the different ways of hosting multiple websites using IIS, and will guide you thru setting IIS 6.0 up to host multiple websites using the host header approach.
How IIS can host multiple websites
To distinguish between websites, IIS looks at three attributes:
- The host header name
- The IP number
- The port number
For each website, the combination of these three attributes must be unique. This means that you can have two websites using two different IP numbers, two different ports, or two different host headers (and of course also any combination of the three). Whatever combination you select, it is stored in the metabase property called ServerBindings in the string format IP:Port:Hostname, for example 192.168.0.1:80:www.gafvert.info. Luckily enough, you do not need to understand anything of the metabase nor the ServerBindings property to follow this article.
The host header name and IP number can be omitted and in that case the website accepts all host header names and/or (depending on if both attributes were omitted) IP numbers. This can of course only be done for one website (otherwise IIS would be confused and would not know which website should handle the request).
What is a host header?
A host header is a string part of the request sent to the web server (it is in the HTTP header). This means that configuring IIS to use host headers is only one step in the approach to host multiple websites using host headers to distinguish between the websites. A configuration of the DNS server (usually means that you need to add an (A) record for the domain) is also required, so the client can find the web server.
Setting up IIS for multiple websites
Now when we have some background and understand how IIS works in relation to hosting multiple websites, and that the DNS server (also known as name server) must be updated to include the new domain, we can start with the configuration of IIS.
Configuring IIS for this is actually not difficult at all. I will use a default installation of Windows Server 2003 Standard Edition, and a default installation of IIS (also see Install and configure IIS 6.0 to serve ASP, ASP.NET and static pages).
- Open IIS Manager
- Right click the "Web Sites" folder and click New->Web Site
- Click Next when the "Web Site Creation Wizard" starts.
- Type a description of the website and click Next. The description has nothing to do with how the clients access the website; it is only a description that you, the website administrator, use to know which website it is.
- Enter the IP Address or use "All unassigned", the port number and the host header name and then click Next. In this example I used "All unassigned", port 80 and a host header name of beta.gafvert.info.
- Enter the path to the home directory and click Next. This directory do not have to be in the Inetpub or wwwroot folder, it can be anywhere on the file system. In this example I placed it on the D: drive in the folder D:\webs\beta.
- Set the access permissions for the new website and click Next. By default, only read access is allowed, and unless you need to, do not change.
- Click Finish.
You have now successfully configured IIS to host two websites, using a host header to distinguish the second website.
The next step is to add an (A) record for beta.gafvert.info (the example) in the DNS server. How to do this depends on the DNS server, and what user interface you have to configure the DNS server, so a step-by-step guide for this has been excluded. This step must however be done, or else your visitors will not be able to find the web server.
A DNS Server is not necessary. The hosts file can also be used, but that means the hosts file must be edited on each client. A CNAME can also be used instead of an (A) record. What is important however is that the client machine must find the web server by using the name you have chosen as host header name, and how the client does this is not related to IIS.
The most critical part of this is actually outside of IIS it is the name resolution. So most problems when setting up multiple websites is that the client is unable to find the server. If this is true can easily be checked:
- Open a command prompt (Start->Run, cmd)
- Type "nslookup beta.gafvert.info" (without the quotes, and replace beta.gafvert.info with the name you want to test)
The IP address returned by nslookup should match the IP address of the web server. If it does not, the problem is related to name resolution and cannot be fixed by an IIS configuration. That is, the DNS server, hosts file, or whatever you use so that the clients find the web server is incorrect configured.
Another common problem reveals itself during the Web Site Creation Wizard; you are unable to create the website with the combination of host header, IP and port you want to. This means that the combination you try to use is not unique, and you will have to check the websites already configured on the server.
A third common problem is that although you use the domain name you have specified to reach the website, you are taken to the "default website" (or any other website that has been configured without host header and listens on the same port number and IP number). This has two possible explanations the website is not properly configured, or IIS does not receive the host header. The latter sounds very uncommon, but is actually quite common. First of all, the Host header is part of the HTTP 1.1 specification, so if the client is using HTTP 1.0, this is expected (all new clients use HTTP 1.1). Second, if the DNS service you use is not true DNS but instead some kind of forwarding service, it happens that the host header is vanished somewhere. So the tip is that if you experience this, verify that IIS actually gets the host header you expect it to get. This problem is rarely related to IIS (since there is not much that can go wrong in the configuration of IIS).
A "400 Bad Request (Invalid Hostname)" is returned if the above problem is true, but there is no "default website" that accepts all requests on that IP number and port.
Understanding Host Headers in IIS
Test host header configuration with the hosts file
Host Headers versus multiple IPs when hosting several websites
Multiple websites on Windows XP Professional
Can I use host headers to run multiple FTP sites?
Append a host header to a website in IIS by code
Configuring SSL Host Headers (IIS 6.0)
Host Header field in RFC 2626 ("Hypertext Transfer Protocol -- HTTP/1.1") section 14.23