When you install Internet Information Services (IIS) on Windows, an empty “Default Web Site” is created by default and listens on the standard web HTTP port – TCP 80. In IIS terms, this means that this site is bind to the port TCP/80. To open this site, just enter the name of the IIS server (
“http://web-srv1”) or its IP address (
“http://192.168.1.100”) in your browser. A single IIS web server can serve dozens and hundreds of websites, and you can run multiple web sites on it, listening and responding on the same TCP port (80, 443, or whatever). However, the interface of IIS Manager does not make it evident that you can host another website without binding it to some other port (e. g., 8080). In this article we’ll show how to host multiple websites on the same IIS server and bind them to the same port and IP address, or to different IP addresses.
IIS Web Site Binding
A single web IIS server running on Windows Server can host multiple websites. However, in order IIS to distribute HTTP requests correctly, each website has to be identified with some unique value. In case of an IIS website, it consists of three attributes that make up a unique combination for each website. These are:
- a TCP port number
- an IP address
- a host header (host name)
The information about the hosted websites is stored in the ServerBindings attribute of the IIS metabase in the following format:
IP:Port:Hostname. Thus, if you want to host multiple websites on the same port and IP address, you will have to use a unique Host header. What is it? Host header is a part of an HTTP request to the server sent by a client that specifies which website it is addressed to. Accordingly, this host header must be specified on the side of the web server, and the DNS contains the correct record that matches the hostname and the IP address of the IIS web server.
Let’s suppose that you have a website running on IIS and listening 80 port. And you need to bind second website to the same port.
In the IIS Manager, create another website (Add Website) with the name TestSite, which files will be located in c:\inetpub\TestSite (do not specify the hostname yet).
After you click OK, a warning appears that you cannot use the binding *:80 for both sites.
Add Website The binding '*:80:' is assigned to another site. If you assign the same binding to this site, you will only be able to start one of the sites. Are you sure that you want to add this duplicate binding?
Agree to this warning. So you have got another site bound to port 80, you cannot start it without stopping the first site.
Hosting Multiple Website on IIS using Host Headers
To create a unique binding, specify another name (Host Name) for the second IIS website. Right-click TestSite and select Edit Bindings. Select the binding you need and click Edit.
Specify the unique host name the users will address to, like TestSite, in the Host Name field.
You can configure the IIS site binding using the command prompt. In this case, for IIS 7 or newer the command to configure the binding looks like this:
C:\Windows\System32\inetsrv\appcmd.exe set site /site.name:testsite /+bindings.[protocol='http',bindingInformation='*:80:testsite']
Now you can start the second website as well.
All you have to do is to add a DNS alias for the server (A or CNAME) to pointing to the IP address or the hostname of your IIS web server. If you are using an Active Directory domain, you need to create DNS records on the domain controller.
You can create a CNAME record for the name testsite in the DNS console (
dnsmgmt.msc) and specify the domain name of your IIS server as FQDN target host.
Add-DnsServerResourceRecordCName -HostNameAlias web-srv1.woshub.com -Name testsite -ZoneName woshub.com
Try to open
http://TestSite in your browser. It should open successfully.
Here are some useful notes worth to be mentioned.
If you are using a standalone IIS server, the mapping of site names to the server’s IP address is done via the file
The bind settings are stored in the IIS configuration file <sites> section of the IIS config file
In our case, this section contains the following data:
<sites> <site name="Default Web Site" id="1"> <application path="/"> <virtualDirectory path="/" physicalPath="%SystemDrive%\inetpub\wwwroot" /> </application> <bindings> <binding protocol="http" bindingInformation="*:80:" /> </bindings> </site> <site name="TestSite" id="2" serverAutoStart="true"> <application path="/" applicationPool="TestSite"> <virtualDirectory path="/" physicalPath="C:\inetpub\TestSite" /> </application> <bindings> <binding protocol="http" bindingInformation="*:80:TestSite" /> </bindings> </site> <siteDefaults> <logFile logFormat="W3C" directory="%SystemDrive%\inetpub\logs\LogFiles" /> <traceFailedRequestsLogging directory="%SystemDrive%\inetpub\logs\FailedReqLogFiles" /> </siteDefaults> <applicationDefaults applicationPool="DefaultAppPool" /> <virtualDirectoryDefaults allowSubDirConfig="true" /> </sites>
Likewise, you can host and run several hundred sites on the same port of your IIS web server.
Run Multiple Sites with Different IP Addresses on IIS
Now let’s try to run two sites on the IIS web server at different IP addresses. First of all, you need to add a separate VLAN interface on Windows Server or simply assign an additional IP address (alias) to your NIC.
In this example, the server has the main IP address 192.168.13.100, and I will add an additional IP alias 192.168.13.101 to the same network adapter:
Get-NetIPAddress | ft IPAddress, InterfaceAlias, SkipAsSource
New-NetIPAddress –IPAddress 192.168.13.101 –PrefixLength 24 –InterfaceAlias “Ethernet” –SkipAsSource $True
Now you need to create an A record for the new site on the DNS server (we will additionally create a PTR record in the reverse zone with the –CreatePtr option):
Add-DnsServerResourceRecordA -Name NewSite3 -IPv4Address 192.168.13.101 -ZoneName woshub.com -TimeToLive 01:00:00 –CreatePtr
It remains to open the Site Binding settings and bind the site to the additional IP address of your host.
Managing IIS Site Bindings Using PowerShell
You can manage the binding of sites on an IIS server using PowerShell. For this, the WebAdministration module is used:
Display information about all available IIS sites and their bindings:
Or about a single site:
(Get-Website -Name NewSite).bindings.Collection
protocol bindingInformation sslFlags -------- ------------------ -------- http 192.168.13.101:80:NewSite3 0
To change the binding of this site (you can change the IP addresses, port or name):
Set-WebBinding -Name NewSite1 -BindingInformation "192.168.13.101:80:NewSite1" -PropertyName 'Port' -Value '8080'
Set-WebBinding -Name NewSite1 -BindingInformation "192.168.13.101:8080:NewSite1" -PropertyName 'IPAddress' -Value '192.168.13.100'
To add a new binding to the specific IIS site, run:
New-IISSiteBinding -Name NewSite1 -BindingInformation "*:9090:" -Protocol http
To remove a binding:
Remove-IISSiteBinding -Name NewSite1 -BindingInformation "*:9090:"
Thus, you can run several sites on the IIS web server both on different IP addresses and on the same IP address and TCP port number.