Creating Multiple SharePoint 2010/2013 Web Applications in Single Port

Setting up a SharePoint web application is fun and easy if we know some of the basics of web application hosting. Recently I came across the question of how to host multiple SharePoint web applications on a single port. Initially I did not understand the purpose of this question in the first place but then I gradually realized that many people do not have the experience / chance to work with hosting web applications. So I decided to right an article to help people in the right direction.

How a client communicates

First we need to know how a client communicates with a server.

A user type is a URL in the browser, for example http://www.examplemydomain.com, then the browser tries to resolve the domain name using a DNS Server / host file in the machine. Once the IP address is provided it will send a http request (GET) to the server with the following sample information.

GET /index.htm HTTP/1.1

Host: www.examplemydomain.com


Once the request reaches the web server it will look at the unique combination of the host header name, IP address and port number to identify the correct web application. So when we setup a web application we must ensure there is a unique entry for each web application.

client-communicate-server.jpg

Alternate Access Mapping

In addition to IIS, SharePoint also comes with AAM settings that tells SharePoint how to map web requests to the correct web application and site so that SharePoint can serve the correct content back to you. It then tells SharePoint what URL the users should be taken to as they interact with SharePoint. AAM allows you to expose a web application in as many as 5 different AAM zones, with a different IIS Web site backing each zone. Go to SharePoint "Central Admininstration" -> "System Settings" -> "Farm Management".

Alternate-Access-Mapping.jpg

The following figure shows two web applications pointing to the same port with different domain names.

Alternate-Access-Mapping1.jpg

You can read more about alternate access mapping at the following links.

http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?PageType=4&ListId={72C1C85B-1D2D-4A4A-90DE-CA74A7808184}&pID=804
http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?PageType=4&ListId={72C1C85B-1D2D-4A4A-90DE-CA74A7808184}&pID=795
http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?PageType=4&ListId={72C1C85B-1D2D-4A4A-90DE-CA74A7808184}&pID=778

How to create SharePoint web application with hostheader

Go to SharePoint "Central Admininstration" -> "Application Management" -> "Manage Web Application".

Create-SharePoint-web-application-with-hostheader.jpg

Create a New Web Application.

Create-a-New-Web-Application.jpg

Specify the Host header in the new web application screen.

Host-header-in-new-web-application-screen.jpg

Repeat the same steps for the next web application and give a different host header.

Host-header-in-new-web-application-screen1.jpg

Now we have two SharePoint web applications with the same port number but different host header, if we look at the bindings for the specified web application in IIS you will see the host header added. (This will be done by the SharePoint during the web application creation.) Go ahead and create a site collection under each web application.

Now it's time to test it locally then hosting the file becomes handy. We must open the hosts file available at "c:\windows\system32\drivers\etc\" and the host entries for each application looks like the following:

127.0.0.1 exampledomain.one.com
127.0.0.1 exampledomain.two.com

One thing to remember is that a host file entry does not require a port number even if you are hosting in a port that is not 80.

Now open up the browser in the local machine and browse to http:// exampledomain.one.com and http://exampledomain.one.com