本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
高级迁移方案
本节介绍复杂 IIS 部署的高级迁移方案。
使用应用程序请求路由 (ARR) 进行多站点迁移
该eb migrate命令会在迁移期间自动检测并保留 ARR 配置。当它识别出您的 IIS 中的 ARR 设置时applicationHost.config
,它会生成必要的 PowerShell 脚本,以便在目标 EC2 实例上重新安装和配置 ARR。
ARR 配置检测
迁移过程将检查 IIS 中的三个关键配置部分:
-
system.webServer/proxy
: 核心 ARR 代理设置 -
system.webServer/rewrite
: 网址重写规则 -
system.webServer/caching
: 缓存配置
例如,考虑一个常见的 ARR 配置,其中在端口 80 上RouterSite
运行的代理分别向端口 8081 和 8082 发出请求,APIService
并在端口 8081 和 8082 上AdminPortal
运行:
<!-- Original IIS ARR Configuration -->
<rewrite>
<rules>
<rule name="Route to API" stopProcessing="true">
<match url="^api/(.*)$" />
<action type="Rewrite" url="http://backend:8081/api/{R:1}" />
</rule>
<rule name="Route to Admin" stopProcessing="true">
<match url="^admin/(.*)$" />
<action type="Rewrite" url="http://backend:8082/admin/{R:1}" />
</rule>
</rules>
</rewrite>
下图描述了这些规则如何隐藏在 IIS 服务器的端口 80 后面,而不是通过 EC2 安全组公开。Application Load Balancer 只能访问端口 80,来自该端口的所有流量都通过端口 80 路由到目标组。

以下命令可以迁移此配置:
PS C:\migrations_workspace>
eb migrate --sites "RouterSite,APIService,AdminPortal" ` --copy-firewall-config
ARR 迁移流程
迁移过程通过几个步骤保留您的 ARR 配置。
- 配置导出
-
该工具将您现有的 ARR 设置从三个关键配置部分导出到存储在
ebmigrateScripts
目录中的单独的 XML 文件中:ebmigrateScripts\ ├── arr_config_proxy.xml ├── arr_config_rewrite.xml └── arr_config_caching.xml
- 安装脚本
-
生成两个 PowerShell 脚本来处理 ARR 设置:
-
arr_msi_installer.ps1
: 下载并安装 ARR 模块 -
arr_configuration_importer_script.ps1
: 导入导出的 ARR 配置
-
- 部署清单集成
-
这些脚本通过以下中的条目集成到部署过程中
aws-windows-deployment-manifest.json
:{ "manifestVersion": 1, "deployments": { "custom": [ { "name": "WindowsProxyFeatureEnabler", "scripts": { "install": { "file": "ebmigrateScripts\\windows_proxy_feature_enabler.ps1" } } }, { "name": "ArrConfigurationImporterScript", "scripts": { "install": { "file": "ebmigrateScripts\\arr_configuration_importer_script.ps1" } } } ] } }
负载均衡器集成
迁移过程会尽可能将您的 ARR 规则转换为 Application Load Balancer (ALB) 侦听器规则。例如,上述 ARR 配置生成 ALB 规则,这些规则基于 URL 路径模式路由流量,同时在 EC2 实例上维护内部路由。
由此产生的环境可维护您的 ARR 路由逻辑,同时充分利用其 Amazon弹性基础架构。您的应用程序继续像以前一样运行,ARR 处理内部路由,而 Application Load Balancer 管理外部流量分配。
使用基于主机的路由实现没有 ARR 的多站点迁移
虽然应用程序请求路由 (ARR) 是在 IIS 中管理多个站点的常用方法,但您也可以利用应用程序负载均衡器的基于主机的路由功能,将多站点部署直接迁移到没有 ARR 的 Elastic Beanstalk。这种方法可以省去额外的路由层,从而降低复杂性并提高性能。
基于主机的路由概述
在这种方法中,每个 IIS 站点都暴露在 EC2 实例之外,Application Load Balancer 会根据主机标头将流量直接路由到相应的端口。这消除了对 ARR 的需求,同时保持了应用程序之间的分离。
考虑一个包含三个站点的多站点 IIS 配置,每个站点都有自己的主机名绑定:
<sites> <site name="Default Web Site" id="1"> <bindings> <binding protocol="http" bindingInformation="*:8081:www.example.com" /> </bindings> </site> <site name="InternalAPI" id="2"> <bindings> <binding protocol="http" bindingInformation="*:8082:api.internal" /> </bindings> </site> <site name="ReportingPortal" id="3"> <bindings> <binding protocol="http" bindingInformation="*:8083:reports.internal" /> </bindings> </site> </sites>
这些站点通过安全组在端口 8081、8082 和 8083 上 EC2 公开。Application Load Balancer 根据负载平衡器侦听器规则配置路由到它们。

迁移过程
要在不使用 ARR 的情况下将此配置迁移到 Elastic Beanstalk,eb migrate请使用以下示例中的命令:
PS C:\migrations_workspace>
eb migrate --sites "Default Web Site,InternalAPI,ReportingPortal"
迁移过程会自动使用基于主机的路由规则配置 Application Load Balancer,这些规则根据主机标头将流量引导到相应的目标组。每个目标组将流量转发到您的 EC2 实例上的相应端口:
主机标头 www.example.com → 端口 8081 上的目标群组
主机标头 api.internal → 端口 8082 上的目标组
主机标头报告。internal → 端口 8083 上的目标组
SSL/TLS 配置
要使用 SSL/TLS 保护您的应用程序,请执行以下步骤:
-
通过 Amazon Certificate Manager(ACM) 为您的域名申请证书。
-
使用这些证书在 Application Load Balancer 上配置 HTTPS 侦听器。
-
更新您的环境配置,使其包含具有以下配置选项设置的 HTTPS 侦听器。
option_settings: aws:elb:listener:443: ListenerProtocol: HTTPS SSLCertificateId: arn:aws:acm:region:account-id:certificate/certificate-id InstancePort: 80 InstanceProtocol: HTTP
使用此配置,SSL 终止发生在负载均衡器上,流量将通过 HTTP 转发到您的实例。这简化了证书管理,同时保持了与客户端的安全连接。
最佳实践
- 安全组
-
将安全组配置为仅允许来自 Application Load Balancer 安全组的 IIS 站点(本示例中为 8081、8082、8083)使用的端口上的入站流量。
- 运行状况检查
-
为每个目标组配置运行状况检查,以确保流量仅路由到运行状况良好的实例。为每个应用程序创建运行状况检查终端节点(如果它们尚不存在)。
- 监控
-
设置 CloudWatch 警报以分别监控每个目标组的运行状况和性能。这使您可以识别特定于各个应用程序的问题。
- 扩展
-
在配置 auto Scaling 策略时,请考虑所有应用程序的资源需求。如果一个应用程序的资源需求明显不同,可以考虑将其迁移到另一个环境。
虚拟目录管理
在将 IIS 应用程序迁移到 Elastic Beanstalk 时,该eb migrate命令可以保留虚拟目录结构。
默认权限配置
迁移虚拟目录时,通过授予对以下内容的 ReadAndExecute 访问权限来eb migrate建立一组基准权限:
-
IIS_IUSRS
-
IUSR
-
经过身份验证的用户
例如,考虑一个典型的虚拟目录结构:
<site name="CorporatePortal">
<application path="/" applicationPool="CorporatePortalPool">
<virtualDirectory path="/" physicalPath="C:\sites\portal" />
<virtualDirectory path="/shared" physicalPath="C:\shared\content" />
<virtualDirectory path="/reports" physicalPath="D:\reports" />
</application>
</site>
受密码保护的虚拟目录
当eb migrate遇到受密码保护的虚拟目录时,它会发出警告并需要手动干预。
以下配置示例将导致该示例之后的警告响应。
<virtualDirectory path="/secure"
physicalPath="C:\secure\content"
userName="DOMAIN\User"
password="[encrypted]" />
[WARNING] CorporatePortal/secure is hosted at C:\secure\content which is password-protected and won't be copied.
要维护密码保护,请创建如下所示的自定义部署脚本:
# PS C:\migrations_workspace> cat secure_vdir_config.ps1 $vdirPath = "C:\secure\content" $siteName = "CorporatePortal" $vdirName = "secure" $username = "DOMAIN\User" $password = "SecurePassword" # Ensure directory exists if (-not (Test-Path $vdirPath)) { Write-Host "Creating directory: $vdirPath" New-Item -Path $vdirPath -ItemType Directory -Force } # Configure virtual directory with credentials Write-Host "Configuring protected virtual directory: $vdirName" New-WebVirtualDirectory -Site $siteName -Name $vdirName ` -PhysicalPath $vdirPath -UserName $username -Password $password # Set additional permissions as needed $acl = Get-Acl $vdirPath $rule = New-Object System.Security.AccessControl.FileSystemAccessRule( $username, "ReadAndExecute", "ContainerInherit,ObjectInherit", "None", "Allow" ) $acl.AddAccessRule($rule) Set-Acl $vdirPath $acl
将此脚本包含在清单中,将其添加到您的部署中:
{ "manifestVersion": 1, "deployments": { "custom": [ { "name": "SecureVirtualDirectory", "scripts": { "install": { "file": "secure_vdir_config.ps1" } } } ] } }
自定义权限管理
该eb migrate命令为自定义权限脚本提供了一个框架,以适应需要默认权限以外的权限的应用程序。
$paths = @( "C:\sites\portal\uploads", "C:\shared\content" ) foreach ($path in $paths) { if (-not (Test-Path $path)) { Write-Host "Creating directory: $path" New-Item -Path $path -ItemType Directory -Force } $acl = Get-Acl $path # Add custom permissions $customRules = @( # Application Pool Identity - Full Control [System.Security.AccessControl.FileSystemAccessRule]::new( "IIS AppPool\CorporatePortalPool", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow" ), # Custom Service Account [System.Security.AccessControl.FileSystemAccessRule]::new( "NT SERVICE\CustomService", "Modify", "ContainerInherit,ObjectInherit", "None", "Allow" ) ) foreach ($rule in $customRules) { $acl.AddAccessRule($rule) } Set-Acl $path $acl Write-Host "Custom permissions applied to: $path" }
最佳实践
遵循这些最佳实践来规划、执行、监控和验证您的迁移。
- 迁移前规划
-
迁移前记录现有权限和身份验证要求。在部署到生产环境之前,先在开发环境中测试自定义权限脚本。
- 共享内容管理
-
对于共享内容目录,请确保通过自定义脚本正确配置了所有必需的文件系统权限。考虑使用 FSx 适用于 Windows 的 Amazon 文件服务器
来满足共享存储需求。 - 监测和核查
-
迁移后监控应用程序日志,以验证对虚拟目录的访问是否正确。请特别注意以下方面:
-
应用程序池身份访问权限
-
自定义服务账号权限
-
网络共享连接
-
身份验证失败次数
-
自定义应用程序池设置
默认情况下,该eb migrate命令不会复制自定义应用程序池设置。要保留自定义应用程序池配置,请按照以下步骤创建和应用自定义清单部分。
-
创建迁移对象的存档。
PS C:\migrations_workspace>
eb migrate --archive
-
创建用于配置应用程序池的自定义 PowerShell 脚本。
# PS C:\migrations_workspace> cat .\migrations\latest\upload_target\customize_application_pool_config.ps1 $configPath = "$env:windir\System32\inetsrv\config\applicationHost.config" [xml]$config = Get-Content -Path $configPath $newPoolXml = @" <!-- Original IIS Configuration --> <applicationPools> <add name="CustomPool" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated"> <processModel identityType="SpecificUser" userName="AppPoolUser" password="[encrypted]" /> <recycling> <periodicRestart time="00:00:00"> <schedule> <add value="02:00:00" /> <add value="14:00:00" /> </schedule> </periodicRestart> </recycling> </add> </applicationPools> "@ $newPoolXmlNode = [xml]$newPoolXml # Find the applicationPools section $applicationPools = $config.SelectSingleNode("//configuration/system.applicationHost/applicationPools") # Import the new node into the document $importedNode = $config.ImportNode($newPoolXmlNode.DocumentElement, $true) $applicationPools.AppendChild($importedNode) # Save the changes $config.Save($configPath) Write-Host "ApplicationHost.config has been updated successfully."
-
更新
aws-windows-deployment-manifest.json
文件以包含您的自定义脚本。{ "manifestVersion": 1, "deployments": { ... "custom": [ ..., { "name": "ModifyApplicationPoolConfig", "description": "Modify application pool configuration from source machine to remove", "scripts": { "install": { "file": "customize_application_pool_config.ps1" }, "restart": { "file": "ebmigrateScripts\\noop.ps1" }, "uninstall": { "file": "ebmigrateScripts\\noop.ps1" } } } ] } }
-
使用更新的存档目录创建环境。
PS C:\migrations_workspace>
eb migrate ` --archive-dir '.\migrations\latest\upload_target\'
该--archive-dir
参数告诉eb migrate使用它之前创建的源代码,从而避免创建新的存档。
部署以前的版本
在 Elastic Beanstalk 中通过带有时间戳的目录和应用程序版本来eb migrate维护您的迁移历史记录。每次迁移都会创建一个唯一的 zip 文件,可以根据需要进行部署。
PS C:\migrations_workspace>
ls .\migrations\
Mode LastWriteTime Length Name ---- ------------- ------ ---- d----l 3/18/2025 10:34 PM latest d----- 3/16/2025 5:47 AM migration_1742104049.479849 d----- 3/17/2025 9:18 PM migration_1742246303.18056 d----- 3/17/2025 9:22 PM migration_1742246546.565739 ... d----- 3/18/2025 10:34 PM migration_1742337258.30742
latest
符号链接始终指向最近创建的迁移对象目录。除了相关的应用程序和错误日志外,每个迁移工件目录还包含一个可以部署到 Elastic Beanstalk 的upload_target.zip
文件。
PS C:\migrations_workspace>
ls .\migrations\latest\
Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 3/18/2025 10:34 PM upload_target -a---- 3/18/2025 10:34 PM 13137 application.log -a---- 3/18/2025 10:34 PM 0 error.log -a---- 3/18/2025 10:34 PM 1650642 upload_target.zip
你可以使用以下方法部署upload_target.zip
文件eb migrate:
PS C:\migrations_workspace>
eb migrate --zip .\migrations\latest\upload_target.zip