When you install an IIS (Internet Information Services) web server on Windows, an empty “Default Web Site” is created, listening on the default HTTP port 80. In this article, we will find out how to host multiple websites on an IIS web server and bind them to the same HTTP or HTTPS port and one or more IP addresses.
Running Multiple Websites on IIS Server using Host Headers
Assuming you’ve already created an HTTPS website on IIS running on port TCP:443 (How to install SSL certificate on IIS).
Create a second site in the IIS management console (inetmgr
). Click Site -> Add website. Specify the name of the site (TestSite) and the path to the site files directory (c:\inetpub\TestSite). Specify HTTPS
type, port 443
, select an SSL certificate in the Bindings section. Don’t specify a hostname yet.
When you try to start a new website, you get an error saying that one port (443) is used by multiple sites. Only one IIS site can run on this port at a time.
This website cannot be started. Another website may be using the same port.
For the IIS web server to correctly distribute HTTP requests across multiple sites, each site must have a unique identifier. In IIS, such an identifier is defined by three attributes:
- TCP port number
- IP address
- Host name (host header)
The value of these attributes for each site is stored in the ServerBindings attribute of the IIS metabase in the following format: IP:Port:Hostname
. If the values of all three attributes are the same for two sites, IIS won’t be able to start the second site. To run a second site on the same port and IP address, you need to give it a unique name (host header) and create a DNS record that matches the name of the site to its IP address.
So, to run a second site, you need to go to Edit Bindings -> Edit and add a unique DNS name for this site to the Host header. For example, testsite.contoso.com.
IIS website binding settings are stored in the IIS configuration file (C:\Windows\System32\inetsrv\config\applicationHost.config
) in the <sites>
section.
You can also configure IIS site binding from the command prompt:
C:\Windows\System32\inetsrv\appcmd.exe Appcmd.exe set site "testsite" /bindings:"https://testsite.contoso.com:443"
You can now start the second site.
Add a DNS entry for the name of your new website. This can be an A or CNAME record pointing to the IP address or hostname of the IIS web server.
If you are deploying a web server in an Active Directory domain zone, create a DNS record on the domain controller. You can use the DNS console (dnsmgmt.msc
) to create a CNAME record. Specify the name of your host running IIS as the FQDN target host.
It is also possible to use PowerShell to create a DNS record:
Add-DnsServerResourceRecordCName -HostNameAlias web-srv1.contoso.com -Name testsite -ZoneName contoso.com
You can now open your second website https://testsite.contoso.com in a browser.
You can use the URL Rewrite module to enable the redirection of the IIS web address from HTTP to HTTPS.
C:\Windows\system32\drivers\etc\hosts
).Run Multiple Websites with Different IP Addresses on IIS
The IIS web server also allows you to host sites on different IP addresses. First, add an additional IP address to Windows. This can be done by adding a separate VLAN interface or by assigning an additional IP address (alias) to the network interface.
In this example, the IP address of the Windows Server host is 192.168.13.100. Let’s add an additional IP address 192.168.13.101 to the same network adaptor:
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 also create a PTR record in the reverse lookup zone by adding the –CreatePtr
option):
Add-DnsServerResourceRecordA -Name NewSite3 -IPv4Address 192.168.13.101 -ZoneName contoso.com -TimeToLive 01:00:00 –CreatePtr
Then bind the site to the new IP address in the Site Binding configuration.
Managing IIS Web Site Bindings with PowerShell
You can manage website binding on the IIS server using the built-in PowerShell WebAdministration module:
Import-Module WebAdministration
View information about all available IIS sites and their bindings:
Get-IISSite
Or about a particular website:
(Get-Website -Name testsite).bindings.Collection
Change the TCP port of the website from 443 to 81:
Set-WebBinding -Name testsite -BindingInformation "*:443:testsite.contoso.com" -PropertyName 'Port' -Value '81'
Change the IP address of the website:
Set-WebBinding -Name testsite -BindingInformation "192.168.13.101:81:testsite.contoso.com" -PropertyName 'IPAddress' -Value '192.168.13.100'
Add a new IIS site binding:
New-IISSiteBinding -Name testsite -BindingInformation "*:8080:" -Protocol http
Remove website binding:
Remove-IISSiteBinding -Name NewSite3 -BindingInformation "*:9090:"
This allows you to run multiple sites on the IIS web server, both on different IP addresses and on the same IP address and/or TCP port.
4 comments
[…] کنید و مطالعه : Run Multiple Websites on the Same Port and IP Address on IIS | Windows OS Hub Mohammad Rasoul Rasti There's no place like 127.0.0.1 m.rasti [@] outlook.com […]
I did as you suggested for an application that require Windows Authentication. The one that reply when the host name is “localhost”, works fine, whilst the second one that reply on a different host name (the one that I defined in file hosts as 127.0.0.1) request the authentication three tiimes and then fails with 401 code.
Any suggestion?
Try to create an A record in your DNS instead of a line in the hosts file.
Very good article but I don’t have any servers in Server Manager under Windows 10. I believe that’s expected but how to add a DNS server there? Can