loading...

Windows Server 2016 – Using host headers to manage multiple websites on a single IP address

How to create virtual machines with VirtualBox

As we just saw, it is pretty straightforward to configure multiple websites inside IIS by assigning individual IP addresses for each site. It is common to run more than one site on a single web server, and so this sometimes means that your web servers have numerous IP addresses configured on them. However, sometimes this is not possible. For example, you may be working on a web server that is Internet facing and there is a restriction on the amount of available public IP addresses that can be used. In this case, you may run across the need to host multiple websites on a single IP address, but you don’t want to force the users into having to type in specific port numbers in order to gain access to the right website.

This is where host headers come into play. Host headers can be configured on your websites so that the site responds to a particular request coming in from the client. These header requests can help the web server distinguish between traffic, directing users calling for websites to their appropriate site inside IIS. Let’s work together to set up two websites inside IIS and force them to utilize the same IP address and port. We want everything to remain standard as far as the port goes, so we want them to both be able to utilize port 80, but we only have one IP address available to install on our web server.

Getting ready

The work will be accomplished from inside IIS on our Server 2016 web server. We will also utilize a client computer to test connectivity to the websites once we are finished setting them up.

How to do it…

To create two websites that share the same IP address and split traffic by using host headers, follow these steps:

  1. On your web server, open up File Explorer and create a new folder called C:\Websites. Inside this folder, create two new folders and call them Site1 and Site2.
  2. Inside each folder, create a new Default.htm file. You should now have two different Default.htm files, one sitting inside the Site1 folder, and one sitting inside the Site2 folder. These will be our example websites.
  1. Put some text inside each of those Default.htm files. Make sure that whatever text you write in them distinguishes between the websites so that we can know it is working properly when we test in a few minutes.
  2. Open Internet Information Services (IIS) Manager from the Tools menu of Server Manager.
  3. In the left-hand window pane, expand the name of your web server. Then right-click on the Sites folder, and choose Add Website….
  4. We are going to name our site Site1 and choose our C:\Websites\Site1 folder as the location for this website. I am also going to drop down the IP address field and specify the one and only IP address on this system so that we can prove host headers are working as they should. Remember, our intention is to get two websites running on this same IP address and port combination.
  5. Here’s the part that may be new territory for you, the Host name field. This is the DNS name that requests for this website will be coming in with. So whatever DNS name your users are going to type into their browser is the name that you need to enter here. We are going to use mysite1.mydomain.local:
  1. Click OK, and you have the first website up and running on the web server.
  2. Now walk through the same process as above, but this time specify all of the information for Site2. We are going to choose the same IP address and Port, but we are going to specify a different name in the Host name field:
  1. We now have two websites, both running on the same IP address and port on the same web server. Let’s test to find out whether or not IIS is smart enough to distinguish between the sites when we try to browse these websites from our client computer.
Remember to create DNS records for these websites! You will need host records created for mysite1.mydomain.local and mysite2.mydomain.local, and they both need to be pointed at the IP address of the web server, which in our case is 10.0.0.6.
  1. On a client computer, browse to http://mysite1.mydomain.local. You should see the text from the Default.htm file that we put into the Site1 folder on the web server:
  1. Now browse to http://mysite2.mydomain.local. We can see that the web server recognizes our request for the second site, and even though they are running on the same IP address, our request is sent over to the second website:

How it works…

When we set up websites inside IIS to utilize different host headers, it gives us the ability to publish multiple sites on the same IP address and port numbers. This can be very useful in cases where IP addresses are limited or where you don’t want to configure multiple addresses onto the web server for any reason. IIS is capable of listening on the same IP and port for web requests coming into different host names and forwarding those requests on to the appropriate website based on the host header name that was requested by the client computer. It is important to note that requests for these web pages must come by the name for this to work properly; you cannot type the IP address of the website into the browser and expect it to work, since we are now sharing that IP address between two or more different sites.

Comments are closed.

loading...