It is often required to host multiple websites on a single instance of IIS, mostly in development environments instead of on production servers. I am sure it is not much a preferred solution on production servers but this is at least a possible implementation.
The benefits of multiple websites on single instance of web server are:
Reduced hardware cost
Reduced resource consumption
Reduced physical space requirement
Alongside benefits there are limitations. Production servers usually have load balancers which roughly and by layman means same website on multiple servers. Therefore, a single server with multiple websites does have limitations in terms of the maximum possible load they can handle. There might be a resource problem if there is a heavy user base.
Not only IIS, other web servers like Apache also support hosting multiple websites on a single web server. Multiple websites hosted on a single web server need to differ in one of the three primary parameters while hosted:
Host header name
Multiple websites using multiple IP addresses
When hosting two web sites (or more) on one web server we can associate the two web sites with two different IP addresses. Different configured web sites can be accessed with the configured IP addresses. For example,
Web site 1 - http://10.5.5.1
Web site 2 - http://10.5.5.2
Physically there is only one server machine which has two registered IP addresses but different IP addresses on the machine are mapped with different web sites.
Open the IIS Manager, which you can find in Administrative Tools or by typing its executable name (inetmgr.exe) into a command prompt or run window
Right-click the web server name to open the context menu
Select Add Web Site…
Fill details on the popup which appears. Make sure you select a valid IP Address under binding section. Insert site name, default app pool, physical path and other values.
For second web site, follow steps #2 to #4. On step #4 enter different site name, physical path and IP Address. Set the IP Address 10.5.5.1 as per the example.
Adding multiple IP addresses to a machine is a hardware configuration which might differ by server hardware configuration. Ideally servers with multiple IP addresses have multiple NIC devices. In that case each NIC has a unique IP address. For example there are two NICs added to the server and one of which is configured to have IP 10.5.5.1 and the other to have 10.5.5.2
Alternatively, when there is only one NIC available to server then same NIC might be configured with two different IP addresses.
Both the cases are explained in the snapshot below where multiple NICs are shown with blue outline. From the Properties window the IP can be set to the NIC. The yellow marker represents the IP address configuration (IPv4) and the example is setting two different IP addresses to same NIC.
Multiple websites using multiple host header name
When hosting two web sites (or more) on one web server we can associate the two web sites with two different host names. Different configured web sites can be accessed with different configured host names. For example,
Web site 1 - http://www.one.com
Web site 2 - http://www.two.com
Provided that the configured domain names are registered with same IP Address when accessible on Internet. For example,
Name = www.one.com, IP = 10.5.5.1
Name = www.two.com, IP = 10.5.5.1
If the server is accessible on Intranet then the server name and IP entry should be made in the domain name server (DNS server) of the local network.
To configure multiple web sites on a single server using the host header approach, all the steps will be same as above except step #4
When filling in the form to add a web site, multiple web sites will have different Host name configuration. For example:
Web site 1
Web site 2
Multiple websites using multiple port numbers
When hosting two web sites (or more) on one web server we can associate the two web sites with two different port numbers on same IP address and host name. Different configured web sites can be accessed with different configured ports. For example,
Web site 1 - http://www.one.com:8080
Web site 1 - http://www.one.com:8081
If the server is accessible on Intranet then the server name and IP entry should be made in the domain server of the local network.
To configure multiple web sites on single server all the steps will be the same as those for multiple IP Addresses or multiple host header name, except step #4
When filling the form to add web site, multiple web sites will have different port number configuration. For example:
Web site 1 with port 8080
Web site 2 with port 8081
These different approaches can be combined together and single server might host multiple websites using two different IP addresses (or may be more than that which is subjected to the hardware configuration) and multiple host header names along with the other approach of different port numbers.
The number of permutations/combinations might be tried till the server is capable of handling the load. Its not a real life scenario to have such a hosted server but worth a try on demo servers at least.
You can totally separate out different demo websites of different purposes which will help controlling the availability of website on random basis without stopping the web server.
Other possible use of the approaches might be during the maintenance of main website or upgrade of the website. You can keep one version of the website always running while you are running maintenance task on the other website. The server can also be load balanced a hardware as well as software.
To try this out on a standalone machine where neither multiple network cards nor the domain networks are available we would add MS loopback adapter in the network adapters and set multiple static IP Addresses in these added adapters and then modify the hosts file to map different URLs with different IP addresses.
On W7 machine, loopback adapter can be added using hdwwiz.exe and selecting Microsoft Loopback Adapter from the list of adapters.
The hosts file can be found at c:\Windows\System32\driver
s\etc. Due to the security introduced by User Account Control (UAC) the text editor might need opened in elevated access mode (runas admin) to edit hosts file.