Configure multiple websites with IIS

更新时间:
复制 MD 格式

Hosting multiple websites on a single ECS instance reduces operational costs and simplifies management tasks, such as software updates, security configurations, and data backups. It also lets you flexibly allocate resources based on each website's needs. This topic describes how to use Internet Information Services (IIS) to host multiple websites on an ECS instance that runs Windows Server 2012 R2 64-bit.

Prerequisites

You have created an ECS instance and deployed a web environment. For more information, see Quickly deploy a BT-Panel.

In this tutorial, you will use IIS on Windows to build two test websites, windows-testpage-1 and windows-testpage-2. You will configure them to be accessible through different domain names on the same port.

Create the test websites

  1. Establish a remote connection to the ECS instance where the web environment is deployed.

  2. On the desktop, click This PC and navigate to the default website root directory at C:\wwwroot.

  3. Create two folders named windows-testpage-1 and windows-testpage-2.

    wwwroot

  4. In the windows-testpage-1 folder, create a test file named test1.php with the following content.

    <?php
    echo "<title>Test-1</title>";
    echo "windows-test-1";
    ?>
  5. In the windows-testpage-2 folder, create a test file named test2.php with the following content.

    <?php
    echo "<title>Test-2</title>";
    echo "windows-test-2";
    ?>

Configure the IIS server

  1. On the taskbar, click the Server Manager icon server.

  2. In the top menu bar, click Tools > Internet Information Services (IIS) Manager.

  3. In the navigation pane on the left of IIS Manager, click the server name, and then click Sites.

  4. In the Actions pane on the right, click Add Website.... Add the windows-testpage-1 test website, and then click OK.

    The website is configured as follows:netsite1

    Parameters:

    • Site name: Enter windows-testpage-1.

    • Application pool: DefaultAppPool

    • Physical path: Specify the physical path to the windows-testpage-1 folder.

    • Host name: Enter the test domain name test1.com.

  5. In the Actions pane, click Add Website... again. Add the windows-testpage-2 test website, and then click OK.

    The website is configured as follows:netsite2

    Parameters:

    • Site name: Enter windows-testpage-2.

    • Application pool: DefaultAppPool

    • Physical path: Specify the physical path to the windows-testpage-2 folder.

    • Host name: Enter the test domain name test2.com.

    After the websites are added, they appear as shown in the following figure.result

(Optional) Configure the local hosts file

Because this tutorial uses test domain names, you need to configure IP address mapping in the hosts file on your on-premises host. If you are using real domain names to configure your websites, you can skip this step. This tutorial assumes your on-premises host runs Windows.

  1. Navigate to the C:\Windows\System32\drivers\etc directory.

  2. Create a backup of the hosts file.

    Keep the hosts - copy file to restore the original hosts file after testing.

  3. Modify the hosts file.

    Append the following lines to the end of the file. Then, save and close the file.

    <The public IP address of your ECS instance> test1.com
    <The public IP address of your ECS instance> test2.com
  4. Return to the Windows desktop and press Win + R.

  5. In the Run dialog box, enter cmd and click OK.

  6. Run the following command in the command prompt to apply the changes immediately.

    ipconfig /flushdns

Verify the results

On your on-premises host, open a web browser to verify that you can access both test websites.

  • Go to test1.com/test1.php. The windows-testpage-1 website appears, as shown in the following figure.test1.php

  • Go to test2.com/test2.php. The windows-testpage-2 website appears, as shown in the following figure.test2.php

You have successfully hosted multiple websites. In a real-world scenario, you only need to correctly configure the host name and the physical path for each project to make your websites accessible. If you need to install an SSL certificate, see Install an SSL certificate on an IIS server (Windows).

References

If you want to host multiple websites on a Linux instance, see Configure multiple websites by using the Nginx service.