With
IIS 7.0, you can create one or more Web sites to publish your Web
applications and services. Before you create a new Web site, consider
how you want it to be accessible by determining the IP addresses, ports,
and (optionally) host headers that will be used to receive requests for
the site. You will use this information to configure one or more
protocol bindings for the Web site.
In IIS 7.0, each Web site serves as a logical
container for Web applications and virtual directories. When you add a
new Web site in IIS 7.0, IIS creates four different objects:
-
A Web site that defines the site name, ID, bindings, and (optionally) more settings
-
A root application
-
A root virtual directory for the root application, mapping its "/" URL namespace to the Web site’s physical root directory
-
If using IIS Manager, an application pool to
host the Web site’s root application (unless you select one of the
existing application pools)
Important
As a security best practice, log on to
your computer by using an account that does not have administrator
privileges. Then use the Runas command to run IIS Manager as an administrator. For example, at the command prompt, type the following: runas /user:<admin_acct> "%windir%\system32\inetsrv\inetmgr.exe"
To use IIS Manager to create a Web site, in
the Connections pane, expand the IIS computer node, right-click the
Sites node in the tree, and then choose Add Web Site. The result is as
shown in Figure 1.
The
Add Web Site dialog box enables you to create the new Web site by
specifying all of the basic information necessary to create the Web
site: a single binding, the root application, the root virtual
directory, and by default, a new application pool to host the
application. You can also define specific credentials to use when
accessing the content in the site’s root virtual directory.
If you would like to make
additional modifications to the Web site’s settings, you can also choose
to not start the new Web site immediately, leaving it in a stopped
state so that you can set additional configuration before manually
starting it later.
You can also use the following Appcmd command to add new Web site.
appcmd add site /name:string /id:uint /bindings:string /physicalPath:string
Table 1 describes the parameters for this command.
Table 1. Syntax for Appcmd to Add a Web Site
Parameter |
Description |
---|
name |
Minimum required field. The string represents the friendly name of the Web site.
When IIS detects a duplication error in the element attribute value of either /name or /id, the command will fail and the Web site will not be created. |
id |
An unsigned integer indicating the Web
site ID. If this value is omitted, IIS 7.0 increments the highest
existing Web site ID by 1 to be the new Web site ID.
When IIS detects a duplication error in the element attribute value of either /name or /id, the command will fail and the Web site will not be created. |
bindings |
A colon-separated list of the
binding strings, including the protocol, and associated binding
information. HTTP and HTTPS binding information includes the IP address,
port, and host header value. Each binding string is in the form of
[protocol]/[bindingInformation], where the [bindingInformation] for the
HTTP and HTTPS protocols is in the form of [ip|*]:[port]:[host header].
For example, http/*:80:www.contoso.com indicates that the Web site host header name is http://www.contoso.com, and it is bound to all IP addresses on port 80. |
physicalPath |
Represents the root application path for the
Web site. The path can be located in the local computer, for example,
d:\fabrikamhr, or a remote server, for example, \\remoteserver\share.
For a shared remote server, you can specify a custom connectivity user
account, which has access permissions on remote share.
If physicalPath is not specified, the root
application and root virtual directory are not automatically created and
must be added later. |
Note
If you specify the full path %windir%\system32\inetsrv\appcmd.exe, you can run the examples from any path without having to change directories.
The following example creates a new Web site
with site ID 9, a site name of Fabrikam HR (for the Fabrikam human
resources department), hr.fabrikam.com
as the host header value, and the access port specified as a standard
HTTP port. The root path of the Web site is mapped to d:\fabrikamHR
physical folder.
appcmd add site /name:"Fabrikam HR" /id:9
/bindings:http/*:80:hr.fabrikam.com /physicalPath:"d:\fabrikamHR"
Note
Long commands are sometimes shown formatted on multiple lines to fit on the printed page.
Take note of the command output, which
shows that three different objects are created (site, application, and
virtual directory). While in the IIS Manager UI, four different objects
are created, because by default, the IIS Manager creates a new
application for the new Web site. This is because a physicalPath is specified, and IIS creates the root application along with defining the virtual root directory of the Web site.
SITE object "Fabrikam HR/" added
APP object "Fabrikam HR/" added
VDIR object "Fabrikam HR/" added
If you don’t specify physicalPath,
as in the following example, only the site object is created, because
IIS does not have enough information to create the associated
application and virtual directory. As a result, the Web site is created,
but cannot be started until you configure physicalPath.
appcmd add site /name:"Fabrikam Finance"
/bindings:http/*:80/finance.fabrikam.com
Caution
When you create a new Web site via Appcmd without specifying bindings or physicalPath information, the new Web site is created, but you cannot start the Web site.
The following shows the <site> element for the Fabrikam HR Web site that has been created using Appcmd as in the first example in this section.
<sites>
...
<site name="Fabrikam HR" id="9">
<application path="/">
<virtualDirectory path="/" physicalPath="d:\fabrikamHR" />
</application>
<bindings>
<binding protocol="http"
bindingInformation="*:80:hr.fabrikam.com" />
</bindings>
</site>
...
</sites>
Configuring a Web Site’s Bindings
Web
site bindings specify protocol-specific endpoints on which requests to
the Web site are received. Each binding defines the protocol and the
protocol-specific binding information.
Note
Servers that have support for additional
protocols, such as "net.tcp" provided by the Windows Communication
Foundation and "ftp" provided by FTP 7.0, can specify bindings by using
these protocols. Consult the documentation for each of these products to
determine the binding information format each protocol uses.
IIS Web sites will typically contain
bindings that use the HTTP or HTTPS protocols. These bindings specify
endpoint information that designates the IP address, Port number, and
Host Header (if any) to which the Web site will bind when it starts.
This enables IIS Web sites to be hosted using some of the following
setups:
-
A Web site listening on a specific port on all available interfaces.
-
A Web site listening on a specific port
on a specific interface/specific IP address. This may be useful to limit
the accessibility of a Web site to clients on a specific network, such
as an internal network or localhost.
-
A Web site listening on a specific port for a specific host header.
In addition, it is possible to host multiple
Web sites on the same server by using bindings that use distinct ports,
interface addresses, or host headers to differentiate multiple Web
sites. The following outlines different ways for multiple Web sites
bindings:
-
Multiple Web sites listening on different ports.
-
Multiple Web sites listening on the same
port, on different interfaces/IP addresses. This may be done to expose
different Web sites on internal versus external IP addresses of the
server. You can also use it as a technique for hosting multiple Web
sites if each Web site has separate IP addresses bound to the server’s
interfaces.
-
Multiple Web sites listening on the same
port and interface/IP address with different host headers. This
technique is most commonly used to host multiple public Web sites. In
addition, shared Web hosting servers use this technique.
Note
Be
careful when using "All Unassigned" or "*" for the list of interfaces
in an HTTP or HTTPS site binding. This configures the binding to listen
on all interfaces that have not yet been taken by other bindings, and
therefore the interfaces that the binding listens on will be dependent
on what other currently active sites have bindings that use the same
port on some or all of the server’s interfaces. For deterministic
results, consider specifying the list of addresses that you would like
the binding to be active on.
Finally, to use a combination of these setups to achieve the desired accessibility, you can use multiple bindings on each site.
Note
You cannot host multiple Web sites using host
headers on the same port/interface if each Web site requires a separate
secure socket layer (SSL) certificate.
In IIS 7.0, you can use IIS Manager to
configure binding information via the Bindings link in the Actions pane.
IIS 7.0 lets you specify protocol bindings other than HTTP and HTTPS
for the Web site. You can no longer specify an underscore character ( _ )
as part of the host header.
To use IIS Manager to change existing
bindings or configure new bindings for a Web site, expand the IIS
computer node in the Connections pane. Then navigate to the Sites node
and expand the tree view. In the Site tree listing, select the Web site
that you want to change and then click the Bindings link in the Actions
pane. The result is shown in Figure 2. Select the desired binding configuration and click Edit. Alternatively, click Remove to delete the binding.
Note
If you are configuring an HTTPS binding, you
will need to select the SSL certificate for binding, and SSL
certificates must already be installed. You can view certificate
information by clicking the View button at the Add Site Binding dialog
box when editing the Web site’s binding information.
Use the following Appcmd syntax to show the bindings for a specific Web site.
appcmd list site SiteName
To configure a Web site’s bindings, use the following command.
appcmd set site SiteName /bindings:string
Table 2 describes the parameters for this command.
Table 2. Syntax for Appcmd to Set Bindings
Parameter |
Description |
---|
SiteName |
The string represents the friendly name of the Web site. |
bindings |
A colon-separated list of the binding
strings, including the protocol, and associated binding information.
HTTP and HTTPS binding information includes the IP address, port, and
host header value. Each binding string is in the form of
[protocol]/[bindingInformation], where the [bindinginformation] for the
HTTP and HTTPS protocols is in the form of [ip|*]:[port]:[host header].
The host header value can be blank if a specific host header is not
specified.
The list of bindings will replace the current bindings set for the site. |
The following syntax lists Fabrikam HR Web site details, including the site’s binding information.
appcmd list site "Fabrikam HR"
As shown in the following code, the
output indicates that the Fabrikam HR Web site is bound to the HTTP
protocol on port 80 for all IP addresses (*) with the host header value
of hr.fabrikam.com.
SITE "Fabrikam HR" (id:9,bindings:http/*:80:hr.fabrikam.com,state:started)
To configure myhr.fabrikam.com as a new host header in addition to hr.fabrikam.com, use the following syntax.
appcmd set site "Fabrikam HR"
/+bindings.[protocol='http',bindingInformation='*:80:myhr.fabrikam.com']
The preceding syntax adds another binding
at the end of Fabrikam’s existing binding information, specifying a new
host header, the HTTP protocol, and all IP addresses with port 80. Using
the previous example, if you want to change existing binding
information from myhr.fabrikam.com to askhr.fabrikam.com, you would use the following syntax.
appcmd set site "Fabrikam HR"
/bindings.[bindingInformation='*:80:myhr.fabrikam.com'].bindingInformation:*:80:askhr.
fabrikam.com
The bindings for a Web site are stored in the Web site’s <site> element. The following shows the <site> element in the applicationHost.config file after running the preceding Appcmd examples.
<sites>
...
<site name="Fabrikam HR" id="9">
<application path="/">
<virtualDirectory path="/" physicalPath="d:\fabrikamHR" />
</application>
<bindings>
<binding protocol="http"
bindingInformation="*:80:hr.fabrikam.com" />
<binding protocol="http"
bindingInformation="*:80:askhr.fabrikam.com" />
</bindings>
</site>
...
</sites>