Build a Static Website on IIS

Updated: February 29, 2012

Applies To: Windows Server 2012, Windows Server 2012 R2

This document guides you through the process of installing an IIS web server and configuring it to serve static content. Static content is a web page (HTML) that is delivered to the user exactly as stored. By contrast, dynamic content is generated by a web application, such as an ASP.NET, classic ASP, or PHP application. Static content displays the same information for all users; dynamic content can display user-specific information, such as the user name.

A static-content web server is the most basic configuration of IIS for supporting HTML websites. You can use a static-content web server to host internal or external (public) websites. When you install IIS 8, the default installation provides all the IIS modules required to support a static-content web server. The default installation includes the ability to serve static HTML files, documents, and images. IIS 8 supports default documents, directory browsing, logging, and anonymous authentication for the static content server.

In this document

  • Prerequisites

  • Step 1: Install the IIS Web Server

  • Step 2: Add a Website

  • Step 3: Configure Anonymous Authentication

  • Step 4: Configure the Default Documents

  • Step 5: Configure Static Content Compression

  • Next Steps

Prerequisites

To get the most from this tutorial, you must have access to a computer that is running one of the following operating systems:

  • Windows Server® 2012

  • Windows® 8

Step 1: Install the IIS Web Server

You can use the Web Platform Installer (Web PI) to install IIS and applications that run on IIS. The Web PI installs the latest versions of web platform offerings, including updates. To learn more about the Web PI, see Learn more and install the Web PI. If you use the Web PI to install IIS, you can skip to step 2.

You can also perform this procedure by using the Windows user interface (UI) or from a command line.

To install IIS on Windows Server 2012 by using the UI

  1. On the Start page, click the Server Manager tile, and then click OK.

  2. In Server Manager, select Dashboard, and click Add roles and features.

  3. In the Add Roles and Features Wizard, on the Before You Begin page, click Next.

  4. On the Select Installation Type page, select Role-based or Feature-based Installation and click Next

  5. On the Select Destination Server page, select Select a server from the server pool, select the name of your computer, and click Next.

  6. On the Select Server Roles page, select Web Server (IIS), and then click Next.

  7. On the Select Features page, notice the preselected features, and then click Next.

  8. On the Web Server Role (IIS) page, click Next.

  9. On the Select Role Services page, note the preselected role services, and then click Next.

    Note

    Install the IIS 8 default role services for a static-content web server.

  10. On the Confirm Installation Selections page, confirm your selections, and then click Install.

  11. On the Installation Progress page, confirm that your installation of the Web Server (IIS) role and required role services completed successfully, and then click Close.

  12. To verify that IIS installed successfully, enter the following into a web browser:

    https://localhost

    You see the default IIS Welcome page.

To install IIS on Windows 8 by using the UI

  1. On the Start page, type Control Panel, and then click the Control Panel icon in the search results.

  2. In Control Panel, click Programs, and then click Turn Windows features on or off.

  3. In the Windows Features dialog box, click Internet Information Services, and then click OK.

    This action installs the IIS 8 default features. Install only the default features for a static-content web server.

  4. To verify that IIS installed successfully, enter the following into a web browser:

    https://localhost

    You see the default IIS Welcome page.

To Install IIS by using the command line

  • Enter the following command at an elevated command prompt or into a script:

    Start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;IIS-RequestMonitor;IIS-Security;IIS-RequestFiltering;IIS-HttpCompressionStatic;IIS-WebServerManagementTools;IIS-ManagementConsole;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI

Step 2: Add a Website

This step tells you how to add a website to IIS by using the IIS Manager UI, or by running Appcmd.exe commands in a command-line window.

To add a website by using the UI

  1. Open IIS Manager.

    • For Windows Server 2012, on the Start page click the Server Manager tile, and then click OK. In the Server Manager, click the Tools menu, and then click Internet Information Services (IIS) Manager.

    • For Windows 8, on the Start page type Control Panel, and then click the Control Panel icon in the search results. On the Control Panel screen, click System and Security, click Administrative Tools, and then click Internet Information Services (IIS) Manager.

  2. In the Connections pane, right-click the Sites node in the tree, and then click Add Website.

  3. In the Add Website dialog box, enter a friendly name for your website in the Site name box.

  4. If you want to select a different application pool than the one listed in the Application Pool box, click Select. In the Select Application Pool dialog box, select an application pool from the Application Pool list and then click OK.

  5. In the Physical path box, enter the physical path of the website's folder, or click the browse button (...) to navigate the file system to find the folder.

  6. If the physical path that you entered in the previous step is to a remote share, click Connect as to specify credentials that have permission to access the path. If you do not use specific credentials, select the Application user (pass-through authentication) option in the Connect As dialog box.

  7. Select the protocol for the website from the Type list.

  8. . If you must specify a static IP address for the website (by default, this is set to All Unassigned), enter the IP address in the IP address box.

  9. Enter a port number in the Port text box.

  10. Optionally, enter a host header name for the website in the Host Header box.

  11. If you do not have to make any changes to the site, and you want the website to be immediately available, select the Start Web site immediately check box.

  12. Click OK.

To add a website by using the command line

  • Use the following syntax at an elevated command prompt or in a script:

    Note

    For this syntax to work, you either must be in the following directory, or have the directory in your path: %windir%\system32\inetsrv

    appcmd add site /name:string /id:uint /physicalPath:string /bindings:string

    The variable name is the name, and the variable id is a positive integer that you want to assign to the site. The variables name and id are the only variables that are required to add a site by using appcmd. However, if you add a site without specifying the values for the bindings and physicalPath attributes, the site will not be able to start.

    The variable physicalPath is the absolute path of the site content in the file system.

    The variable bindings contains information that is used to access the site. It must be in the form protocol/IP_Address:port:hostheader. For example, for a website, the binding http/*:85: configures the site to listen for HTTP requests on port 85 for all IP addresses and domain names (also known as host headers or host names). On the other hand, a binding of http/*:85:marketing.contoso.com configures a website to listen for HTTP requests on port 85 for all IP addresses and for the domain name marketing.contoso.com.

    To add a website named contoso with an ID of 2 that has content in c:\contoso, and that listens for HTTP requests on port 85 for all IP addresses and a domain name of marketing.contoso.com, enter the following at the command prompt:

    appcmd add site /name:contoso /id:2 /physicalPath:c:\contoso /bindings:http/*:85:marketing.contoso.com

Step 3: Configure Anonymous Authentication

Anonymous authentication gives users access to the public areas of your website without prompting them for a user name or password. You can configure anonymous authentication by using the default anonymous user account (IUSR), or you can set up a local user account for anonymous users.

To configure anonymous authentication by using the UI

  1. In Features View of IIS Manager, double-click Authentication.

  2. On the Authentication page, select Anonymous Authentication.

  3. In the Actions pane, click Edit to set the security principal (user credentials) under which anonymous users will connect to the site.

  4. In the Edit Anonymous Authentication Credentials dialog box, select one of the following options:

    • If you want to configure a specific user account that IIS uses to access your site or application, select Specific user. Then click Set to open the Set Credentials dialog box, and enter a user name and password for the identity. Then click OK.

    • If you want IIS processes to run by using the account that is currently specified on the property page for the application pool, select Application pool identity. By default, this identity is the IUSR account.

      Important

      If you use the IUSR account, you grant anonymous users all the internal network access associated with that account.

  5. Click OK to close the Edit Anonymous Authentication Credentials dialog box.

To configure anonymous authentication by using the command line

  • Use the following syntax to change the default account for anonymous access:

    appcmd set config /section:anonymousAuthentication /userName:string /password:string

    The variable username is the account that IIS uses for anonymous authentication, and the variable password is the password, which is encrypted in the configuration file by default. For example, to use an account named Moe and a password of pssword1 for anonymous access, enter the following at the command prompt:

    appcmd set config /section:anonymousAuthentication /userName:Moe /password:pssword1

Step 4: Configure the Default Documents

When a client request to your website doesn’t include a document name, IIS looks for a file whose name is defined as a default document. Typically, the default document name is Default.htm. You can define a list of default document names in order of precedence.

To configure the default document by using the UI

  1. In Features View of IIS Manager, double-click Default Document.

  2. In the Actions pane, click Add.

  3. In the Name box, enter the file name that you want to add to the list of default documents and then click OK. This file name is added to the top of the default document list.

  4. Optionally, select a default document in the list and in the Actions pane, click Move Up or Move Down to change the file's precedence.

  5. Optionally, select a default document in the list, and in the Actions pane, click Remove to remove any file names that you do not want to use as default documents.

To configure the default document by using the command line

  • To add a file name to the list of default documents, use the following syntax:

    appcmd set config /section:defaultDocument /+files.[value='string']

    The variable string is the file name that you want to add to the list. For example, to add a file named home.html to the default document list, enter the following at the command prompt:

    appcmd set config /section:defaultDocument /+files.[value='home.html']

    To remove a file named home.html from the default document list, enter the following at the command prompt, and then press ENTER:

    appcmd set config /section:defaultDocument /-files.[value='home.html']

Step 5: Configure Static Content Compression

You can optionally configure your web server to compress static content to user bandwidth more efficiently and to enhance the performance of your website.

To configure static content compression by using the UI

  1. In Features View of IIS Manager, double-click Compression.

  2. Select Enable static content compression to configure IIS to compress static content.

  3. In the Static Compression box, configure the following settings:

    1. Optionally, select Only compress files larger than (in bytes) and enter the minimum file size that you want IIS to compress. The default size is 256 bytes.

    2. In the Cache directory text box, enter the path of a local directory or click the browse button () to locate a directory. After a static file is compressed, it is cached in this temporary directory until it expires, or until the content changes. The temporary directory must be on a local drive on an NTFS-formatted partition. The directory cannot be compressed, and should not be shared.

    3. Optionally, select Per application pool disk space limit (in MB) and enter the maximum amount of space per application pool, in megabytes, you want IIS to use when it compresses static content. For example, if there are 20 application pools on the server and the Disk space limit is set to 100, the maximum disk space will be 2GB. If you click the Per application pool disk space limit (in MB) option and enter a number in the text box under it, IIS automatically cleans up the temporary directory according to a least recently used rule when the set limit is reached. The default is 100 MB per application pool.

  4. Click Apply in the Actions pane.

To configure static content compression by using the command line

  • To enable HTTP compression of static content, at the command prompt, enter the following command, and then press Enter:

    appcmd set config /section:urlCompression /doStaticCompression:True

  • To configure static-content compression settings, use the following syntax:

    appcmd set config /section:urlCompression /minFileSizeforComp:int /directory:string /maxDiskSpace:int

    The variable minFileSizeforComp sets the minimum number of bytes that a file must contain for it to be compressed. The default value is 256. The variable directory specifies the directory where compressed versions of static files are temporarily stored and cached. The default is the following folder:

    %SystemDrive%\inetpub\temp\IIS Temporary Compressed Files

    The variable maxDiskSpace sets the maximum amount of space per application pool, in megabytes, that you want IIS to use when it compresses static content. The default is 100 MB per application pool.

Next Steps

Test your website thoroughly to ensure that it functions as expected. Then consider configuring the following features.

See also