Internet Information Service (IIS) can access data in Server Message Block (SMB) file systems in the same way as it accesses data in on-premises disks. IIS provides the web and FTP services to separate website storage from computing. This topic describes how to configure IIS to access a NAS file system.

Prerequisites

Background information

Windows server is a popular platform that is used to build websites. A large number of users build websites on Windows Elastic Compute Service (ECS) instances and store the content resources of the website on a reliable and high-throughput SMB file system. In addition, the computing and storage resources support auto scaling based on specific business requirements.

The FTP service provided by IIS includes a wide range of requirements. A large number of website administrators remotely manage website content by using the FTP service. Meanwhile, a large number of Alibaba Cloud users want to transfer and share files between WANs and Alibaba Cloud by using the FTP service on Windows ECS instances.

In this example, IIS 7.5 (Windows Server 2008 R2) is used to describe how to use NAS to provide both the web service and FTP service for a Windows ECS instance. You can also use Server Load Balancer (SLB) to build a multi-server website that provides error tolerance. For more information, see What is SLB?

Important
  • The topic provides some security suggestions, but they are not a complete security solution. You must devise your own plans to secure your web services and data. For example, you can safeguard your system security by setting up firewalls, configuring security groups for ECS instances, and installing operating system patches. You can also safeguard your service security by using the security services of Alibaba Cloud.
  • In this topic, a normal user named iss_user is used. We recommend that you access data as this user instead of the system administrator when you deploy FTP services or run IIS web services on Windows Server 2016.
Access from IIS to NAS

Install Windows IIS

In this example, Windows Server 2008 R2 is used to describe how to add an IIS role and install IIS by using Server Manager.
Note For more information about how to install IIS on different Windows operating systems, see Install IIS and ASP.NET Modules.
  1. In the Windows server, choose Start > Administrative Tools > Server Manager.
  2. In the left-side navigation pane of the Server Manager dialog box, click Roles. Then, click Add Roles.
  3. In the left-side navigation pane of the Add Roles Wizard, click Server Roles. Then, select Web Server (IIS).
    Select Web Server (IIS)
  4. In the left-side navigation pane of the Add Roles Wizard, click Role Services. Then, select the role services that you want to install for the web server (IIS).

    In addition to the default services, you must also select ASP and FTP Server to enable FTP services and demonstrate dynamic web pages by using scripts.

    Select roles
  5. Click Next and complete the installation as prompted.

Access the SMB file system

You can store your web resources and configuration files in the shared directory (myshare by default) of the SMB file system. You can configure the permission group of the SMB file system to make sure that the web server can read data from and write data to the file system.

  1. Open the File Explorer window and enter \\file-system-id.region.nas.aliyuncs.com\myshare in the address bar to access the SMB file system.
    • file-system-id.region.nas.aliyuncs.com is the domain name of the mount target for the SMB file system. For more information about how to obtain the domain name of the mount target for an SMB file system, see View the endpoint of a mount target.
    • myshare is the default shared directory of the SMB file system. You cannot change this directory.
  2. Create a subdirectory named www in the myshare directory of the SMB file system to store web page files of your website.

    In this example, the static web page file index.html and the dynamic web page file test.asp are created in the myshare\www directory. The following sample code shows how to create the files:

    • Index.html
      <HTML>
        <HEAD>
           <TITLE>Hello World in HTML</TITLE>
        </HEAD>
        <BODY>
           <CENTER><H1>Hello World!</H1></CENTER>
        </BODY>
      </HTML>                         
      Hello World! is displayed in the static web page.
    • Test.asp
      <HTML>
        <BODY>
           This page was last refreshed on <%= Now() %>.
        </BODY>
      </HTML>                            
      The current system time is displayed on the dynamic web page.

Set up the Windows IIS web service

  1. In the Windows server, choose Start > Windows Operating System > Administrative Tools > Internet Information Services (IIS) Manager.
  2. In the left-side navigation pane, choose View Sites > Default Web Site. Then, click Basic Settings.
  3. In the Edit Site dialog box, set Physical path and click OK.

    In the Physical path field, enter the storage path of web resources on NAS, for example, \file-system-id.region.nas.aliyuncs.com\myshare\www. file-system-id.region.nas.aliyuncs.com is the domain name of the mount target for the SMB file system. Replace the domain name with the actual value.

    Configure the physical path
    Note By default, you must use a user account and user group of IIS to access a network drive (for example, Z:\) mapped in the user session. You cannot directly access the mapped network drive as a Windows user. Otherwise, an access error may occur.
  4. Optional:Modify the registry and add the iis_user user.
    To achieve the coordination of IIS and NAS, you must perform the following steps. For Windows Server 2016, you must modify the registry and add the iis_user user. For Windows Server 2019, you must modify the registry, add the iis_user user, and then run the New-SmbGlobalMapping command in PowerShell to mount the SMB file system. The command ensures that dynamic-link libraries (DLLs) can be loaded.
    1. Modify the registry key of the SMB client.
      1. On the Windows server, choose Start > Administrative Tools > Registry Editor.
      2. In the left-side navigation pane of Registry Editor, choose HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > Services > LanmanWorkstation > Parameters > AllowInsecureGuestAuth, right-click a blank area, and then choose New > DWORD (32-bit) Value.
      3. Set the value name to AllowInsecureGuestAuth, set the value data to 1, and then click OK.
    2. Specify a local user to access the web resources stored on NAS.
      1. In the Windows server, choose Start > Windows Operating System > Administrative Tools > Internet Information Services (IIS) Manager.
      2. In the left-side navigation pane, choose View Sites > Default Web Site. Then, click Basic Settings.
      3. In the Edit Site dialog box, click Connect as.
      4. Select Specific User and click Set.
    3. Set the username and password, and then click OK.
      In this example, the iis_user user is used.
    4. Run the New-SmbGlobalMapping command in PowerShell to mount the SMB file system.
      # Define clear text string for username and password
      [string]$userName = 'WORKGROUP\administrator'
      [string]$userPassword = '****'
      
      # Convert to SecureString
      [securestring]$secStringPassword = ConvertTo-SecureString $userPassword -AsPlainText -Force
      
      [pscredential]$credObject = New-Object System.Management.Automation.PSCredential ($userName, $secStringPassword)
      New-SmbGlobalMapping -LocalPath z: -RemotePath \\file-system-id.region.nas.aliyuncs.com\myshare -Persistent $true -Credential $credObject

      **** is the password of the administrator of the operating system. file-system-id.region.nas.aliyuncs.com is the domain name of the mount target for the SMB file system. Replace the domain name with the actual value.

      Note
      • When IIS accesses a file in the shared directory of the NAS file system, the backend of IIS may access the shared directory for multiple times. Although each access request does not take a long time, the client may take a long time to respond if multiple access requests are sent. For more information, see How can I improve access performance from IIS to NAS?
      • We recommend that you store the web-related files such as JS and CSS files to local disks if these files are frequently accessed by IIS.
      • If a write failure still occurs after you perform the preceding operations, contact NAS technical support.
  5. Verify the settings.

    Enter the local paths of the index.html and test.asp files in the address bar of your browser to open these files. If the following figures are displayed, IIS is running as expected. You can also configure security groups for your ECS instances and configure Windows Firewall to ensure access security.

    ResultResult

Set up the Windows IIS FTP service

  1. In the Windows server, choose Start > Windows Operating System > Administrative Tools > Internet Information Services (IIS) Manager.
  2. Install the SSL certificate.
    1. On the homepage, double-click Server Certificates.
      Install the server certificate
    2. On the Server Certificates page, click Create Self-Signed Certificate.
    3. Specify a name for the certificate, and click OK.
  3. Set up an FTP site.
    1. In the left-side navigation pane, double-click Sites.
    2. On the Sites page, click Add FTP Site.
    3. In the Add FTP site dialog box, set the relevant parameters and click Next.

      In the Physical path field, enter the storage path of web resources on NAS, for example, \file-system-id.region.nas.aliyuncs.com\myshare\www. file-system-id.region.nas.aliyuncs.com is the domain name of the mount target. Replace the domain name with the actual value.

      You can select another subdirectory in the myshare directory based on your business requirements. You can also set up multiple FTP sites that provide different ports to access different directories.

      Configure the physical path
    4. In the Binding and SSL Settings dialog box, set the relevant parameters and click Next.
      Set the following parameters:
      • Port: The default port number is 21. For security concerns, port 2222 is used.
      • SSL Certificate: select the created SSL certificate.
      Configure the physical path
    5. Configure the authentication and authorization information, and click Finish.
      Set the following parameters:
      • Authentication: Select Basic.
      • Authorization: Select a user who is allowed to access NAS. In this example, iis_user is used.
      • Permissions: Grant read and write permissions to the user.
      Configure the authentication and authorization information
  4. Set up the FTP firewall.

    On the homepage, double-click FTP Firewall Support dialog box, specify Data Channel Port Range, and then click Apply.

    FTP firewall
  5. In the Server Manager window, restart the FTP service to validate the port range configurations.
    Restart the FTP service
  6. In the ECS console, configure the security group for the ECS instance to restrict the access of FTP clients. For more information, see Create a security group.
  7. Access the FTP site through the FTP client WinSCP.
    1. Open WinSCP.
    2. Click Yes to accept the server certificate.
      Accept the server certificate
    3. Set the protocol type, port number, and logon information.
      Set the protocol type
    4. Enter the password of the authorized user (iis_user).
      Specify a password
    5. Establish a data connection to allow the server to read data from and write data to remote directories.
      Establish a data connection
    6. After the connection is created, you can upload and download files.
      Upload and download data